summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorShireesh Anjal <anjalshireesh@gmail.com>2011-11-24 03:04:55 -0800
committerShireesh Anjal <anjalshireesh@gmail.com>2011-11-24 03:04:55 -0800
commit8a711629ad4e285fe6ef6fe36415907970f7da19 (patch)
tree2b7a8f65daec65fa739bbf7c6cb4a0eb32076176 /src
parentdb063ab2473917904bf770992706b7fe3c144f9e (diff)
parentd826da2b2e7749579d80b87471bd3c073e051ecc (diff)
Merge pull request #6 from TimothyAsir/master
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
-rwxr-xr-xsrc/com.gluster.storage.management.gateway.scripts/src/backend/get_filesystem_type.py4
2 files changed, 38 insertions, 19 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)
diff --git a/src/com.gluster.storage.management.gateway.scripts/src/backend/get_filesystem_type.py b/src/com.gluster.storage.management.gateway.scripts/src/backend/get_filesystem_type.py
index 00cb3a59..de4b4bb0 100755
--- a/src/com.gluster.storage.management.gateway.scripts/src/backend/get_filesystem_type.py
+++ b/src/com.gluster.storage.management.gateway.scripts/src/backend/get_filesystem_type.py
@@ -13,8 +13,10 @@ if not p2 in sys.path:
sys.path.append(p2)
import Utils
+SUPPORTED_FSTYPE = ['ext3', 'ext4', 'ext4dev', 'xfs']
+
def main():
- print "\n".join(Utils.getFileSystemType())
+ print "\n".join(list(set(Utils.getFileSystemType()).intersection(set(SUPPORTED_FSTYPE))))
if __name__ == "__main__":
main()