From f5a733c084dfb3d5db2f8184ad8692b67f3f5092 Mon Sep 17 00:00:00 2001 From: Eric Harney Date: Wed, 6 Mar 2019 10:07:04 -0500 Subject: [PATCH] Revert "Use native python truncate for privsep" This reverts commit 2e292ddeb4148e12b8972fa0a25c03ab4c5e61a8. Related-Bug: #1818504 Change-Id: I3df664d16ed8af4471619904c8af9e3427891ac4 --- cinder/privsep/fs.py | 47 ++------------------------------------------ 1 file changed, 2 insertions(+), 45 deletions(-) diff --git a/cinder/privsep/fs.py b/cinder/privsep/fs.py index e96fbab37d4..f880a6d8c0e 100644 --- a/cinder/privsep/fs.py +++ b/cinder/privsep/fs.py @@ -20,39 +20,9 @@ Helpers for filesystem related routines. from oslo_concurrency import processutils -from oslo_log import log as logging import cinder.privsep -LOG = logging.getLogger(__name__) - -mult_table = {'K': 1024} -mult_table['M'] = mult_table['K'] * 1024 -mult_table['G'] = mult_table['M'] * 1024 -mult_table['T'] = mult_table['G'] * 1024 -mult_table['P'] = mult_table['T'] * 1024 -mult_table['E'] = mult_table['P'] * 1024 - - -def _convert_sizestr(sizestr): - try: - ret = int(sizestr) - return ret - except ValueError: - pass - - error = ValueError(sizestr + " is not a valid sizestr") - - unit = sizestr[-1:].upper() - if unit in mult_table: - try: - ret = int(sizestr[:-1]) * mult_table[unit] - except ValueError: - raise error - return ret - - raise error - @cinder.privsep.sys_admin_pctxt.entrypoint def umount(mountpoint): @@ -60,18 +30,5 @@ def umount(mountpoint): @cinder.privsep.sys_admin_pctxt.entrypoint -def _truncate(size, path): - # On Python 3.6, os.truncate() can accept a path arg. - # For now, do it this way. - with open(path, 'a+b') as f: - f.truncate(size) - - -def truncate(sizestr, path): - # TODO(eharney): change calling code to use bytes instead size strings - size = _convert_sizestr(sizestr) - - LOG.debug('truncating file %(path)s to %(size)s bytes', {'path': path, - 'size': size}) - - _truncate(size, path) +def truncate(size, path): + processutils.execute('truncate', '-s', size, path)