+def _InitSharedFileStorage(shared_file_storage_dir):
+ """Initialize if needed the shared file storage.
+
+ @param shared_file_storage_dir: the user-supplied value
+ @return: either empty string (if file storage was disabled at build
+ time) or the normalized path to the storage directory
+
+ """
+ if not constants.ENABLE_SHARED_FILE_STORAGE:
+ return ""
+
+ shared_file_storage_dir = os.path.normpath(shared_file_storage_dir)
+
+ if not os.path.isabs(shared_file_storage_dir):
+ raise errors.OpPrereqError("The shared file storage directory you"
+ " passed is not an absolute path.",
+ errors.ECODE_INVAL)
+
+ if not os.path.exists(shared_file_storage_dir):
+ try:
+ os.makedirs(shared_file_storage_dir, 0750)
+ except OSError, err:
+ raise errors.OpPrereqError("Cannot create file storage directory"
+ " '%s': %s" % (shared_file_storage_dir, err),
+ errors.ECODE_ENVIRON)
+
+ if not os.path.isdir(shared_file_storage_dir):
+ raise errors.OpPrereqError("The file storage directory '%s' is not"
+ " a directory." % shared_file_storage_dir,
+ errors.ECODE_ENVIRON)
+ return shared_file_storage_dir
+
+