[Ocfs2-tools-devel] [PATCH] mounted.ocfs2 tool should show /dev/mapper devices instead of /dev/dm.

Tristan tristan.ye at oracle.com
Tue Dec 8 22:28:11 PST 2009


xiaowei hu wrote:
> hi Tristan,
>
> yes, I checked this patch use the script,it reports:
> total: 0 errors, 0 warnings, 91 lines checked
>
> what's your check result?
>
> that 2 warning you mentioned,I will fix it :)
>   

Yes, it reported no error when I do it again:-), wondering why it 
complained by the first time...

Tristan.

> thanks
> xiaowei
>
> On Wed, 2009-12-09 at 11:26 +0800, Tristan wrote:
>   
>> Xiaowei,
>>
>> Btw, you'd better check the patch by /linux-source/scripts/checkpatch.pl 
>> after coding completed,
>> and try to kill all of the warnings and errors reported by the 
>> script:-), since I still found some errors
>> when checking the patch.
>>
>> Tristan.
>>
>> XiaoweiHu wrote:
>>     
>>> The mounted.ocfs2 tool should show /dev/mapper devices instead of /dev/dm.
>>> Patch uses the device number to match the dm device with its corresponding
>>> dev-mapper device.
>>>
>>> Signed-off-by: XiaoweiHu <xiaowei.hu at oracle.com>
>>> ---
>>>  mounted.ocfs2/mounted.c |   61 +++++++++++++++++++++++++++++++++++++++++++++-
>>>  1 files changed, 59 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/mounted.ocfs2/mounted.c b/mounted.ocfs2/mounted.c
>>> index e4c5877..a78e6be 100644
>>> --- a/mounted.ocfs2/mounted.c
>>> +++ b/mounted.ocfs2/mounted.c
>>> @@ -33,6 +33,7 @@
>>>  #include <linux/fd.h>
>>>  #include <string.h>
>>>  #include <sys/stat.h>
>>> +#include <dirent.h>
>>>  
>>>  #include <uuid/uuid.h>
>>>  
>>> @@ -155,12 +156,48 @@ static void ocfs2_print_quick_detect(struct list_head *dev_list)
>>>  	}
>>>  }
>>>  
>>> +void scan_dir_for_dev(char *dirname, dev_t devno, char **devname)
>>> +{
>>> +	DIR *dir;
>>> +	struct dirent *dp;
>>> +	char path[PATH_MAX];
>>> +	int dirlen;
>>> +	struct stat st;
>>> +
>>> +	dir = opendir(dirname);
>>> +	if (dir == NULL)
>>> +		return;
>>> +	dirlen = strlen(dirname) + 2;
>>> +	while ((dp = readdir(dir)) != 0) {
>>> +		if (dirlen + strlen(dp->d_name) >= sizeof(path))
>>> +			continue;
>>> +
>>> +		if (dp->d_name[0] == '.' &&
>>> +		    ((dp->d_name[1] == 0) ||
>>> +		     ((dp->d_name[1] == '.') && (dp->d_name[2] == 0))))
>>> +			continue;
>>> +
>>> +		sprintf(path, "%s/%s", dirname, dp->d_name);
>>> +		if (stat(path, &st) < 0)
>>> +			continue;
>>> +
>>> +		if (S_ISBLK(st.st_mode) && st.st_rdev == devno) {
>>> +			*devname = strdup(path);
>>> +			break;
>>> +		}
>>> +	}
>>> +	closedir(dir);
>>> +	return;
>>> +}
>>> +
>>>  static errcode_t ocfs2_partition_list (struct list_head *dev_list)
>>>  {
>>>  	errcode_t ret = 0;
>>>  	FILE *proc;
>>>  	char line[256];
>>>  	char name[256];
>>> +	char *devname = NULL;
>>> +	int major, minor;
>>>  	ocfs2_devices *dev;
>>>  
>>>  	proc = fopen ("/proc/partitions", "r");
>>> @@ -170,14 +207,34 @@ static errcode_t ocfs2_partition_list (struct list_head *dev_list)
>>>  	}
>>>  
>>>  	while (fgets (line, sizeof(line), proc) != NULL) {
>>> -		if (sscanf(line, "%*d %*d %*d %99[^ \t\n]", name) != 1)
>>> +		if (sscanf(line, "%d %d %*d %99[^ \t\n]",
>>> +			   &major, &minor, name) != 3)
>>>  			continue;
>>>  
>>>  		ret = ocfs2_malloc0(sizeof(ocfs2_devices), &dev);
>>>  		if (ret)
>>>  			goto bail;
>>>  
>>> -		snprintf(dev->dev_name, sizeof(dev->dev_name), "/dev/%s", name);
>>> +		/* Try to translate private device-mapper dm-<N> names
>>> +		 * to standard /dev/mapper/<name>.
>>> +		 */
>>> +		if (!strncmp(name, "dm-", 3) && isdigit(name[3])) {
>>> +			devname = NULL;
>>> +			scan_dir_for_dev("/dev/mapper",
>>> +					 makedev(major, minor), &devname);
>>> +			if (devname) {
>>> +				snprintf(dev->dev_name, sizeof(dev->dev_name),
>>> +					 "%s", devname);
>>> +				free(devname);
>>> +			} else
>>> +				snprintf(dev->dev_name, sizeof(dev->dev_name),
>>> +					 "/dev/%s", name);
>>> +
>>> +		} else {
>>> +			snprintf(dev->dev_name, sizeof(dev->dev_name),
>>> +				 "/dev/%s", name);
>>> +		}
>>> +
>>>  		list_add_tail(&(dev->list), dev_list);
>>>  	}
>>>  
>>>   
>>>       
>
>
>   




More information about the Ocfs2-tools-devel mailing list