Allow the user to create a file backstore by specifying a new file name and a size. We create the file and blow it up to the size (will be fast if sparse files are in use. Handle rename of convert_human_to_bytes -> human_to_bytes Signed-off-by: Andy Grover <agrover@xxxxxxxxxx> --- targetcli/ui_backstore.py | 21 ++++++++++++++++++--- 1 files changed, 18 insertions(+), 3 deletions(-) diff --git a/targetcli/ui_backstore.py b/targetcli/ui_backstore.py index d73260d..ad25732 100644 --- a/targetcli/ui_backstore.py +++ b/targetcli/ui_backstore.py @@ -23,7 +23,7 @@ from rtslib import FileIOBackstore, BlockBackstore from rtslib import PSCSIBackstore, RDMCPBackstore from rtslib import FileIOStorageObject, BlockStorageObject from rtslib import PSCSIStorageObject, RDMCPStorageObject -from rtslib.utils import get_block_type, is_disk_partition +from rtslib.utils import get_block_type, is_disk_partition, human_to_bytes from configshell import ExecutionError import os @@ -267,9 +267,24 @@ class UIFileIOBackstore(UIBackstore): if os.path.isfile(file_or_dev): new_size = str(os.path.getsize(file_or_dev)) if size: - self.shell.log.info("%s exists, using its size (%s bytes)" + - " instead" % (file_or_dev, new_size)) + self.shell.log.info("%s exists, using its size (%s bytes) instead" + % (file_or_dev, new_size)) size = new_size + else: + # create file and extend to given file size + if not size: + raise ExecutionError("Attempting to create file for new" + + " fileio backstore, need a size") + + f = open(file_or_dev, "w+") + try: + f.seek(human_to_bytes(size)-1) + f.write('\0') + except IOError: + f.close() + os.remove(file_or_dev) + raise ExecutionError("Could not expand file to size") + f.close() try: so = FileIOStorageObject( -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe target-devel" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html