Change getting major:minor of blkdev
Replace method for determine major:minor of block device because stat can't detect major:minor in some cases. Change-Id: Idcc7cd7a41e225d1052c03ba846dff02851758f8
This commit is contained in:
parent
83bab150b7
commit
1c210d2e49
@ -33,6 +33,27 @@ from swift.common.utils import backward, get_logger, dump_recon_cache, \
|
|||||||
|
|
||||||
def get_devices(device_dir, logger):
|
def get_devices(device_dir, logger):
|
||||||
devices = []
|
devices = []
|
||||||
|
majmin_devices = {}
|
||||||
|
|
||||||
|
# List /dev/block
|
||||||
|
# Using os.scandir on recent versions of python, else os.listdir
|
||||||
|
if 'scandir' in dir(os):
|
||||||
|
with os.scandir("/dev/block") as it:
|
||||||
|
for ent in it:
|
||||||
|
if ent.is_symlink():
|
||||||
|
dev_name = os.path.basename(os.readlink(ent.path))
|
||||||
|
majmin = os.path.basename(ent.path).split(':')
|
||||||
|
majmin_devices[dev_name] = {'major': majmin[0],
|
||||||
|
'minor': majmin[1]}
|
||||||
|
else:
|
||||||
|
for ent in os.listdir("/dev/block"):
|
||||||
|
ent_path = os.path.join("/dev/block", ent)
|
||||||
|
if os.path.is_symlink(ent_path):
|
||||||
|
dev_name = os.path.basename(os.readlink(ent_path))
|
||||||
|
majmin = os.path.basename(ent_path).split(':')
|
||||||
|
majmin_devices[dev_name] = {'major': majmin[0],
|
||||||
|
'minor': majmin[1]}
|
||||||
|
|
||||||
for line in open('/proc/mounts').readlines():
|
for line in open('/proc/mounts').readlines():
|
||||||
data = line.strip().split()
|
data = line.strip().split()
|
||||||
block_device = data[0]
|
block_device = data[0]
|
||||||
@ -41,15 +62,25 @@ def get_devices(device_dir, logger):
|
|||||||
device = {}
|
device = {}
|
||||||
device['mount_point'] = mount_point
|
device['mount_point'] = mount_point
|
||||||
device['block_device'] = block_device
|
device['block_device'] = block_device
|
||||||
try:
|
dev_name = os.path.basename(block_device)
|
||||||
device_num = os.stat(block_device).st_rdev
|
if dev_name in majmin_devices:
|
||||||
except OSError:
|
# If symlink is in /dev/block
|
||||||
# If we can't stat the device, then something weird is going on
|
device['major'] = majmin_devices[dev_name]['major']
|
||||||
logger.error("Error: Could not stat %s!" %
|
device['minor'] = majmin_devices[dev_name]['minor']
|
||||||
block_device)
|
else:
|
||||||
continue
|
# Else we try to stat block_device
|
||||||
device['major'] = str(os.major(device_num))
|
try:
|
||||||
device['minor'] = str(os.minor(device_num))
|
device_num = os.stat(block_device).st_rdev
|
||||||
|
except OSError:
|
||||||
|
# If we can't stat the device,
|
||||||
|
# then something weird is going on
|
||||||
|
logger.error(
|
||||||
|
'Could not determine major:minor numbers for %s '
|
||||||
|
'(mounted at %s)! Skipping...',
|
||||||
|
block_device, mount_point)
|
||||||
|
continue
|
||||||
|
device['major'] = str(os.major(device_num))
|
||||||
|
device['minor'] = str(os.minor(device_num))
|
||||||
devices.append(device)
|
devices.append(device)
|
||||||
for line in open('/proc/partitions').readlines()[2:]:
|
for line in open('/proc/partitions').readlines()[2:]:
|
||||||
major, minor, blocks, kernel_device = line.strip().split()
|
major, minor, blocks, kernel_device = line.strip().split()
|
||||||
@ -85,7 +116,7 @@ def get_errors(error_re, log_file_pattern, minutes, logger,
|
|||||||
# track of the year and month in case the year recently
|
# track of the year and month in case the year recently
|
||||||
# ticked over
|
# ticked over
|
||||||
year = now_time.year
|
year = now_time.year
|
||||||
prev_entry_month = now_time.strftime('%b')
|
prev_ent_month = now_time.strftime('%b')
|
||||||
errors = {}
|
errors = {}
|
||||||
|
|
||||||
reached_old_logs = False
|
reached_old_logs = False
|
||||||
@ -107,11 +138,11 @@ def get_errors(error_re, log_file_pattern, minutes, logger,
|
|||||||
break
|
break
|
||||||
# Solves the problem with year change - kern.log does not
|
# Solves the problem with year change - kern.log does not
|
||||||
# keep track of the year.
|
# keep track of the year.
|
||||||
log_time_entry = line.split()[:3]
|
log_time_ent = line.split()[:3]
|
||||||
if log_time_entry[0] == 'Dec' and prev_entry_month == 'Jan':
|
if log_time_ent[0] == 'Dec' and prev_ent_month == 'Jan':
|
||||||
year -= 1
|
year -= 1
|
||||||
prev_entry_month = log_time_entry[0]
|
prev_ent_month = log_time_ent[0]
|
||||||
log_time_string = '%d %s' % (year, ' '.join(log_time_entry))
|
log_time_string = '%d %s' % (year, ' '.join(log_time_ent))
|
||||||
try:
|
try:
|
||||||
log_time = datetime.datetime.strptime(
|
log_time = datetime.datetime.strptime(
|
||||||
log_time_string, '%Y %b %d %H:%M:%S')
|
log_time_string, '%Y %b %d %H:%M:%S')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user