Hi Lucas,
I gone through the patch for get_disk_list( ) that you have sent. We are
getting the list of all the disks, partitioned as well as unpartitioned.
The only concern is that if we have disks sdc1, sdc2 and sdc3 (sdc1 has root
mounted on it), then in the disk list we are getting the entry for 'sdc' as
well.
So if anyone uses 'sdc' then it will cause a problem.
I have tried few things on this issue, Please go through it once, if it looks
fine to you.
I will generate the patch for the same once you are done with changes for
get_disk_list( ).
I tried to apply that patch you sent but its giving error 'Patch format
detection failed.' , so I will generate the patch for the following thing later.
for i in hd_list:
if i['mountpt'] != None and not i['device'].isalpha():
tmp = i['device']
tmp = tmp.strip('0123456789')
for x in hd_list:
if x['device'] == tmp:
hd_list.remove(x)
return hd_list
Thanks and regards,
Shrirang
________________________________________
From: Lucas Meneghel Rodrigues [[email protected]]
Sent: Tuesday, July 05, 2011 2:20 AM
To: [email protected]
Cc: Shrirang Phansalkar; Lucas Meneghel Rodrigues
Subject: [PATCH] Add option to fsdev_disks.get_disk_list() to get unpartitioned
devices
From: Shrirang Phansalkar <[email protected]>
The default behavior of the function fsdev_disks.get_disk_list()
is to return only partitions, rather than possibly unpartitioned
disks (ie, it would return /dev/sdc3 but not an unpartitioned
/dev/sdd). Let's add an option that makes all devices to be
returned, with defaults to the original behavior.
Also, turned a large chunk of content on part of the docstring
for that particular function.
Signed-off-by: Shrirang Phansalkar <[email protected]>
Signed-off-by: Lucas Meneghel Rodrigues <[email protected]>
---
client/bin/fsdev_disks.py | 85 ++++++++++++++++++++++++--------------------
1 files changed, 46 insertions(+), 39 deletions(-)
diff --git a/client/bin/fsdev_disks.py b/client/bin/fsdev_disks.py
index a4cb390..d7f4fa7 100644
--- a/client/bin/fsdev_disks.py
+++ b/client/bin/fsdev_disks.py
@@ -10,37 +10,47 @@ fd_mgr = fsdev_mgr.FsdevManager()
# scheduler tunables.
_DISKPART_FILE = '/proc/partitions'
-##############################################################################
-#
-# The 'disk_list' array returned by get_disk_list() has an entry for each
-# disk drive we find on the box. Each of these entries is a map with the
-# following 3 string values:
-#
-# 'device' disk device name (i.e. the part after /dev/)
-# 'mountpt' disk mount path
-# 'tunable' disk name for setting scheduler tunables (/sys/block/sd??)
-#
-# The last value is an integer that indicates the current mount status
-# of the drive:
-#
-# 'mounted' 0 = not currently mounted
-# 1 = mounted r/w on the expected path
-# -1 = mounted readonly or at an unexpected path
-#
-# When the 'std_mounts_only' argument is True we don't include drives
-# mounted on 'unusual' mount points in the result.
-#
-##############################################################################
-def get_disk_list(std_mounts_only=True):
+def get_disk_list(std_mounts_only=True, get_all_disks=False):
+ """
+ Get a list of dictionaries with information about disks on this system.
+
+ @param std_mounts_only: Whether the function should return only disks that
+ have a mount point defined (True) or even devices that doesn't
+ (False).
+
+ @param get_all_disks: Whether the function should return only partitioned
+ disks (False) or return every disk, regardless of being partitioned
+ or not (True).
+
+ @return: List of dictionaries with disk information (see more below).
+
+ The 'disk_list' array returned by get_disk_list() has an entry for each
+ disk drive we find on the box. Each of these entries is a map with the
+ following 3 string values:
+
+ 'device' disk device name (i.e. the part after /dev/)
+ 'mountpt' disk mount path
+ 'tunable' disk name for setting scheduler tunables
(/sys/block/sd??)
+
+ The last value is an integer that indicates the current mount status
+ of the drive:
+
+ 'mounted' 0 = not currently mounted
+ 1 = mounted r/w on the expected path
+ -1 = mounted readonly or at an unexpected path
+ When the 'std_mounts_only' argument is True we don't include drives
+ mounted on 'unusual' mount points in the result.
+ """
# Get hold of the currently mounted file systems
mounts = utils.system_output('mount').splitlines()
# Grab all the interesting disk partition names from /proc/partitions,
# and build up the table of drives present in the system.
hd_list = []
- hd_regexp = re.compile("([hs]d[a-z]+3)$")
+ # h for IDE drives, s for SATA/SCSI drives, v for Virtio drives
+ hd_regexp = re.compile("([hsv]d[a-z]+3)$")
partfile = open(_DISKPART_FILE)
for partline in partfile:
@@ -51,9 +61,11 @@ def get_disk_list(std_mounts_only=True):
# Get hold of the partition name
partname = parts[3]
- # The partition name better end with a digit
- if not partname[-1:].isdigit():
- continue
+ if not get_all_disks:
+ # The partition name better end with a digit
+ # (get only partitioned disks)
+ if not partname[-1:].isdigit():
+ continue
# Process any site-specific filters on the partition name
if not fd_mgr.use_partition(partname):
@@ -67,15 +79,11 @@ def get_disk_list(std_mounts_only=True):
fstype = ''
fsopts = ''
fsmkfs = '?'
-
# Prepare the full device path for matching
chkdev = '/dev/' + partname
- # If the partition is mounted, we'll record the mount point
mountpt = None
-
for mln in mounts:
-
splt = mln.split()
# Typical 'mount' output line looks like this (indices
@@ -84,7 +92,7 @@ def get_disk_list(std_mounts_only=True):
# <device> on <mount_point> type <fstp> <options>
# 0 1 2 3 4 5
- if splt[0] == chkdev:
+ if splt[0].strip() == chkdev.strip():
# Make sure the mount point looks reasonable
mountpt = fd_mgr.check_mount_point(partname, splt[2])
@@ -100,7 +108,6 @@ def get_disk_list(std_mounts_only=True):
if fsopts[:3] != '(rw':
mstat = -1
break
-
# The drive is mounted at the 'normal' mount point
mstat = 1
@@ -108,13 +115,13 @@ def get_disk_list(std_mounts_only=True):
if std_mounts_only and mstat < 0:
continue
- # Was this partition mounted at all?
- if not mountpt:
- # Ask the client where we should mount this partition
- mountpt = fd_mgr.check_mount_point(partname, None)
+ if not get_all_disks:
+ # Was this partition mounted at all?
if not mountpt:
- # Client doesn't know where to mount partition - ignore it
- continue
+ mountpt = fd_mgr.check_mount_point(partname, None)
+ # Ask the client where we should mount this partition
+ if not mountpt:
+ continue
# Looks like we have a valid disk drive, add it to the list
hd_list.append({ 'device' : partname,
--
1.7.6
PROPRIETARY-CONFIDENTIAL INFORMATION INCLUDED
This electronic transmission, and any documents attached hereto, may contain
confidential, proprietary and/or legally privileged information. The
information is intended only for use by the recipient named above. If you
received this electronic message in error, please notify the sender and delete
the electronic message. Any disclosure, copying, distribution, or use of the
contents of information received in error is strictly prohibited, and violators
will be pursued legally.
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest