summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTimothy Asir <tjeyasin@redhat.com>2011-11-24 14:39:39 +0530
committerTimothy Asir <tjeyasin@redhat.com>2011-11-24 14:39:39 +0530
commit36343ba85f7655d612858bbe51f29e9ca226b226 (patch)
tree6bd080c902732af7b129d416342b60a4a38b340a /src
parent4acfc6825765ab5d757271ee48bca7c79801ec65 (diff)
Enhanced format_device.py and added check for the device and it's size based on file system type.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/com.gluster.storage.management.gateway.scripts/src/backend/format_device.py53
1 files changed, 35 insertions, 18 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 5cdfd1c9..8630635c 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
@@ -5,6 +5,7 @@
import os
import sys
+import stat
p1 = os.path.abspath(os.path.dirname(sys.argv[0]))
p2 = "%s/common" % os.path.dirname(p1)
if not p1 in sys.path:
@@ -15,10 +16,11 @@ import Globals
import Utils
import DiskUtils
+SIZE_TB_16 = 17179869184L
def main():
if Utils.runCommand("wget -t 1 -T 1 -q -O /dev/null %s" % Globals.AWS_WEB_SERVICE_URL) == 0:
- sys.stderr.write("format device unsupported")
+ sys.stderr.write("format device unsupported\n")
sys.exit(1)
if len(sys.argv) != 4:
@@ -28,37 +30,52 @@ def main():
fsType = sys.argv[1]
mountPoint = sys.argv[2]
device = DiskUtils.getDevice(sys.argv[3])
+ deviceName = DiskUtils.getDeviceName(sys.argv[3])
+
+ if not os.path.exists(device):
+ sys.stderr.write("device %s not found\n" % sys.argv[3])
+ sys.exit(2)
+
+ try:
+ if not stat.S_ISBLK(os.stat(device).st_mode):
+ sys.stderr.write("%s is not a block device\n" % sys.argv[3])
+ sys.exit(3)
+ except OSError, e:
+ Utils.log("unable to get device %s mode: %s" % (device, str(e)))
+ sys.stderr.write("unable to get device %s mode\n" % sys.argv[3])
+ sys.exit(-2)
+
+ if fsType in ['ext3', 'ext4', 'ext4dev']:
+ deviceSize = DiskUtils.getProcPartitions()[deviceName]['Size']
+ if deviceSize >= SIZE_TB_16:
+ Utils.log("device %s, size %s is greater than %s size for fstype %s" % (device, deviceSize, SIZE_TB_16, fsType))
+ sys.stderr.write("size of device %s is unsupported for fstype %s\n" % (sys.argv[3], fsType))
+ sys.exit(4)
if DiskUtils.isDataDiskPartitionFormatted(device):
- Utils.log("device %s already formatted" % device)
sys.stderr.write("device %s already formatted\n" % sys.argv[3])
- sys.exit(2)
+ sys.exit(5)
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)
+ sys.exit(6)
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)
+ sys.exit(7)
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)
+ sys.exit(8)
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)
+ sys.exit(9)
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)
+ sys.stderr.write("unsupported file system type %s\n" % fsType)
+ sys.exit(10)
deviceFormatLockFile = Utils.getDeviceFormatLockFile(device)
deviceFormatStatusFile = Utils.getDeviceFormatStatusFile(device)
@@ -69,18 +86,18 @@ def main():
line = Utils.readFile(deviceFormatStatusFile)
if not line:
sys.stderr.write("failed to read format status file %s\n" % deviceFormatStatusFile)
- sys.exit(-2)
+ sys.exit(-3)
if line.strip().upper() == "COMPLETED":
sys.stderr.write("Device %s already formatted\n" % sys.argv[3])
- sys.exit(8)
+ sys.exit(11)
else:
sys.stderr.write("Formatting device %s already running\n" % sys.argv[3])
- sys.exit(9)
+ sys.exit(12)
if os.path.exists(deviceFormatLockFile):
Utils.log("lock file %s exists" % deviceFormatLockFile)
sys.stderr.write("Formatting device %s already running\n" % sys.argv[3])
- sys.exit(10)
+ sys.exit(13)
command = ["%s/format_device_background.py" % p1, fsType, mountPoint, sys.argv[3]]
Utils.runCommandBG(command)