summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authortimothy <timothy@malar.(none)>2011-11-23 17:46:39 +0530
committertimothy <timothy@malar.(none)>2011-11-23 17:46:39 +0530
commita8048501b4ba5e52ef943aed017e655024f010a0 (patch)
tree4b589ac66f4d5a0fe6e2fa4c4fea7136c7986c72 /src
parent7476d5ee5b3f96ef8b637a4a016634cb1d098187 (diff)
Enhanced format_device.py
Removed gluster_provision_block_wrapper.py Added format_device_background.py
Diffstat (limited to 'src')
-rwxr-xr-xsrc/com.gluster.storage.management.gateway.scripts/src/backend/format_device.py75
-rwxr-xr-xsrc/com.gluster.storage.management.gateway.scripts/src/backend/format_device_background.py (renamed from src/com.gluster.storage.management.gateway.scripts/src/backend/gluster_provision_block_wrapper.py)85
2 files changed, 101 insertions, 59 deletions
diff --git a/src/com.gluster.storage.management.gateway.scripts/src/backend/format_device.py b/src/com.gluster.storage.management.gateway.scripts/src/backend/format_device.py
index 8ae00260..5cdfd1c9 100755
--- a/src/com.gluster.storage.management.gateway.scripts/src/backend/format_device.py
+++ b/src/com.gluster.storage.management.gateway.scripts/src/backend/format_device.py
@@ -14,7 +14,6 @@ if not p2 in sys.path:
import Globals
import Utils
import DiskUtils
-from optparse import OptionParser
def main():
@@ -22,23 +21,49 @@ def main():
sys.stderr.write("format device unsupported")
sys.exit(1)
- parser = OptionParser()
- parser.add_option("-t", "--type", action="store", type="string", dest="fstype")
- (options, args) = parser.parse_args()
-
- if len(args) != 1:
- sys.stderr.write("usage: %s [-t FSTYPE] DEVICE_NAME\n" % os.path.basename(sys.argv[0]))
+ if len(sys.argv) != 4:
+ sys.stderr.write("usage: %s FSTYPE MOUNT_POINT DEVICE_NAME\n" % os.path.basename(sys.argv[0]))
sys.exit(-1)
- device = DiskUtils.getDevice(args[0])
- deviceFormatLockFile = Utils.getDeviceFormatLockFile(device)
- deviceFormatStatusFile = Utils.getDeviceFormatStatusFile(device)
- deviceFormatOutputFile = Utils.getDeviceFormatOutputFile(device)
+ fsType = sys.argv[1]
+ mountPoint = sys.argv[2]
+ device = DiskUtils.getDevice(sys.argv[3])
if DiskUtils.isDataDiskPartitionFormatted(device):
- sys.stderr.write("Device already formatted\n")
+ Utils.log("device %s already formatted" % device)
+ sys.stderr.write("device %s already formatted\n" % sys.argv[3])
sys.exit(2)
+ if os.path.exists(mountPoint):
+ if not os.path.isdir(mountPoint):
+ Utils.log("mount point %s exists but not a directory" % mountPoint)
+ sys.stderr.write("mount point %s exists but not a directory" % mountPoint)
+ sys.exit(3)
+ procMounts = Utils.readFile("/proc/mounts")
+ if procMounts.find(" %s " % mountPoint) != -1:
+ Utils.log("mount point %s already has a mount" % mountPoint)
+ sys.stderr.write("mount point %s already has a mount\n" % mountPoint)
+ sys.exit(4)
+ if procMounts.find(" %s/" % mountPoint) != -1:
+ Utils.log("mount point %s has a submount" % mountPoint)
+ sys.stderr.write("mount point %s has a submount\n" % mountPoint)
+ sys.exit(5)
+ else:
+ status = Utils.runCommand("mkdir -p %s" % mountPoint, output=True, root=True)
+ if status["Status"] != 0:
+ Utils.log("failed to create mount point %s" % mountPoint)
+ sys.stderr.write("failed to create mount point %s\n" % mountPoint)
+ sys.exit(6)
+
+ if fsType not in Utils.getFileSystemType():
+ Utils.log("invalid file system type %s" % fsType)
+ sys.stderr.write("invalid file system type %s\n" % fsType)
+ sys.exit(7)
+
+ deviceFormatLockFile = Utils.getDeviceFormatLockFile(device)
+ deviceFormatStatusFile = Utils.getDeviceFormatStatusFile(device)
+ deviceFormatOutputFile = Utils.getDeviceFormatOutputFile(device)
+
if os.path.exists(deviceFormatStatusFile):
Utils.log("format status file %s exists" % deviceFormatStatusFile)
line = Utils.readFile(deviceFormatStatusFile)
@@ -46,29 +71,19 @@ def main():
sys.stderr.write("failed to read format status file %s\n" % deviceFormatStatusFile)
sys.exit(-2)
if line.strip().upper() == "COMPLETED":
- sys.stderr.write("Device already formatted\n")
- sys.exit(3)
+ sys.stderr.write("Device %s already formatted\n" % sys.argv[3])
+ sys.exit(8)
else:
- sys.stderr.write("Device format already running\n")
- sys.exit(4)
+ sys.stderr.write("Formatting device %s already running\n" % sys.argv[3])
+ sys.exit(9)
if os.path.exists(deviceFormatLockFile):
Utils.log("lock file %s exists" % deviceFormatLockFile)
- sys.stderr.write("Device format already running\n")
- sys.exit(5)
-
- if options.fstype:
- command = ["%s/gluster_provision_block_wrapper.py" % p1, "-t", "%s" % (options.fstype), "%s" % (device)]
- else:
- command = ["%s/gluster_provision_block_wrapper.py" % p1, "%s" % (device)]
+ sys.stderr.write("Formatting device %s already running\n" % sys.argv[3])
+ sys.exit(10)
- try:
- pid = os.fork()
- except OSError, e:
- Utils.log("failed to fork a child process: %s" % str(e))
- sys.exit(6)
- if pid == 0:
- os.execv(command[0], command)
+ command = ["%s/format_device_background.py" % p1, fsType, mountPoint, sys.argv[3]]
+ Utils.runCommandBG(command)
sys.exit(0)
diff --git a/src/com.gluster.storage.management.gateway.scripts/src/backend/gluster_provision_block_wrapper.py b/src/com.gluster.storage.management.gateway.scripts/src/backend/format_device_background.py
index a2827ea2..a804a59c 100755
--- a/src/com.gluster.storage.management.gateway.scripts/src/backend/gluster_provision_block_wrapper.py
+++ b/src/com.gluster.storage.management.gateway.scripts/src/backend/format_device_background.py
@@ -11,9 +11,9 @@ if not p1 in sys.path:
sys.path.append(p1)
if not p2 in sys.path:
sys.path.append(p2)
-import subprocess
import Utils
-from optparse import OptionParser
+import FsTabUtils
+import DiskUtils
def writeStatus(deviceFormatStatusFile, message):
try:
@@ -25,17 +25,15 @@ def writeStatus(deviceFormatStatusFile, message):
return False
return True
-
def main():
- parser = OptionParser()
- parser.add_option("-t", "--type", action="store", type="string", dest="fstype")
- (options, args) = parser.parse_args()
-
- if len(args) != 1:
- sys.stderr.write("usage: %s [-t FSTYPE] DEVICE" % os.path.basename(sys.argv[0]))
+ if len(sys.argv) != 4:
+ sys.stderr.write("usage: %s FSTYPE MOUNT_POINT DEVICE_NAME\n" % os.path.basename(sys.argv[0]))
sys.exit(-1)
- device = args[0]
+ fsType = sys.argv[1]
+ mountPoint = sys.argv[2]
+ device = DiskUtils.getDevice(sys.argv[3])
+
deviceFormatLockFile = Utils.getDeviceFormatLockFile(device)
deviceFormatStatusFile = Utils.getDeviceFormatStatusFile(device)
deviceFormatOutputFile = Utils.getDeviceFormatOutputFile(device)
@@ -54,7 +52,7 @@ def main():
except OSError, e:
Utils.log("failed to create lock file %s: %s" % (deviceFormatLockFile, str(e)))
writeStatus(deviceFormatStatusFile, "Lock file creation failed\n")
- sys.exit(3)
+ sys.exit(-2)
try:
fptr = open(deviceFormatOutputFile, 'w')
@@ -62,36 +60,65 @@ def main():
Utils.log("failed to create output file %s" % deviceFormatOutputFile)
writeStatus(deviceFormatStatusFile, "Output file creation failed\n")
Utils.removeFile(deviceFormatLockFile)
- sys.exit(4)
+ sys.exit(-3)
- if options.fstype:
- command = "gluster-provision-block -t %s %s" % (options.fstype, device)
- else:
- command = "gluster-provision-block %s" % (device)
-
- process = Utils.runCommandBG(command,
- stdinFileObj=subprocess.PIPE,
- stdoutFileObj=fptr,
- stderrFileObj=subprocess.PIPE)
- if process:
- status = process.wait()
+ if fsType in ['ext3', 'ext4', 'ext4dev']:
+ command = "/sbin/mkfs.%s -F -I 512 %s" % (fsType, device)
+ elif fsType == "xfs":
+ command = "/sbin/mkfs.%s -f -i size=512 %s" % (fsType, device)
else:
+ command = "/sbin/mkfs.%s %s" % (fsType, device)
+
+ status = Utils.runCommand(command, output=True, root=True)
+ if status["Status"] != 0:
Utils.removeFile(deviceFormatOutputFile)
Utils.removeFile(deviceFormatLockFile)
writeStatus(deviceFormatStatusFile, "Device format failed\n")
+ sys.exit(3)
+
+ if Utils.runCommand("udevadm trigger") != 0:
+ Utils.log("failed running udevadm trigger")
+
+ if Utils.runCommand("/usr/bin/lshal") != 0:
+ Utils.log("failed running /usr/bin/lshal")
+
+ deviceUuid = DiskUtils.getUuidByDiskPartition(device)
+ if not deviceUuid:
+ Utils.removeFile(deviceFormatOutputFile)
+ Utils.removeFile(deviceFormatLockFile)
+ Utils.log("UUID not found after device %s formatted" % device)
+ writeStatus(deviceFormatStatusFile, "UUID not found after device %s formatted\n" % sys.argv[3])
+ sys.exit(4)
+
+ if DiskUtils.isDataDiskPartitionFormatted(device):
+ Utils.removeFile(deviceFormatOutputFile)
+ Utils.removeFile(deviceFormatLockFile)
+ Utils.log("UUID device %s already has an entry in fstab" % device)
+ writeStatus(deviceFormatStatusFile, "UUID device %s already has an entry in fstab\n" % sys.argv[3])
sys.exit(5)
- if status != 0:
+ newFsTabEntry = {"Device" : "UUID=%s" % deviceUuid,
+ "MountPoint" : mountPoint,
+ "FsType" : fsType,
+ "Options" : "defaults",
+ "DumpOption" : "0",
+ "fsckOrder" : "2"}
+ if fsType in ['ext3', 'ext4', 'ext4dev']:
+ newFsTabEntry["Options"] = "defaults,user_xattr"
+ if not FsTabUtils.addFsTabEntry(newFsTabEntry):
Utils.removeFile(deviceFormatOutputFile)
Utils.removeFile(deviceFormatLockFile)
- writeStatus(deviceFormatStatusFile, "Device format failed\n")
+ writeStatus(deviceFormatStatusFile, "failed to update fstab")
sys.exit(6)
- if Utils.runCommand("/sbin/udevtrigger") != 0:
- Utils.log("failed running /sbin/udevtrigger")
+ status = Utils.runCommand("mount %s" % mountPoint, output=True, root=True)
+ if status["Status"] != 0:
+ Utils.removeFile(deviceFormatOutputFile)
+ Utils.removeFile(deviceFormatLockFile)
+ Utils.log("Mounting device %s on %s failed" % (device, mountPoint))
+ writeStatus(deviceFormatStatusFile, "Mounting device %s on %s failed\n" % (sys.argv[3], mountPoint))
+ sys.exit(7)
- if Utils.runCommand("/usr/bin/lshal") != 0:
- Utils.log("failed running /usr/bin/lshal")
writeStatus(deviceFormatStatusFile, "Completed\n")
Utils.removeFile(deviceFormatOutputFile)
Utils.removeFile(deviceFormatLockFile)