[Ocfs2-tools-devel] [PATCH] mounted.ocfs2: Ignore partitioned whole disk devices

Goldwyn Rodrigues rgoldwyn at gmail.com
Fri May 17 13:57:29 PDT 2013


mounted.ocfs2 processes all devices in /proc/partitions. However, some devices
such as those partitioned can be ignored. This would eliminate false warnings
such as "Unknown: OCFS2 directory corrupted". In the case below,
/dev/sdc is eliminated.

# mounted.ocfs2 -f
Device                FS     Nodes
/dev/sdc              ocfs2  Unknown: OCFS2 directory corrupted
/dev/sdc2             ocfs2  Not mounted
/dev/sdj              ocfs2  Not mounted
/dev/mapper/havg1-data  ocfs2  32086935, 48864151, 15309719, 266967959

Most of the minor number calculations for whole disk is picked up
from e2fsprogs.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn at suse.de>
---
Index: ocfs2-tools/mounted.ocfs2/mounted.c
===================================================================
--- ocfs2-tools.orig/mounted.ocfs2/mounted.c
+++ ocfs2-tools/mounted.ocfs2/mounted.c
@@ -31,6 +31,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <linux/fd.h>
+#include <linux/major.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <dirent.h>
@@ -254,6 +255,58 @@ static void free_partition_list(struct l
  }
 }

+static void list_rm_device(struct list_head *dev_list, int major, int minor)
+{
+ struct list_head *pos1, *pos2;
+ ocfs2_devices *dev;
+
+ list_for_each_safe(pos1, pos2, dev_list) {
+ dev = list_entry(pos1, ocfs2_devices, list);
+ if ((dev->maj_num == major) && (dev->min_num == minor)) {
+ if (dev->map)
+ ocfs2_free(&dev->map);
+ list_del(&(dev->list));
+ ocfs2_free(&dev);
+ }
+ }
+}
+
+static int is_partition(int major, int minor)
+{
+ char path[PATH_MAX + 1];
+ struct stat info;
+
+ snprintf(path, sizeof(path), "/sys/dev/block/%d:%d/partition",
+ major, minor);
+
+ return !stat(path, &info);
+}
+
+static int find_whole_disk_minor(int major, int minor) {
+#ifndef SCSI_BLK_MAJOR
+#ifdef SCSI_DISK0_MAJOR
+#ifdef SCSI_DISK8_MAJOR
+#define SCSI_DISK_MAJOR(M) ((M) == SCSI_DISK0_MAJOR || \
+ ((M) >= SCSI_DISK1_MAJOR && (M) <= SCSI_DISK7_MAJOR) || \
+ ((M) >= SCSI_DISK8_MAJOR && (M) <= SCSI_DISK15_MAJOR))
+#else
+#define SCSI_DISK_MAJOR(M) ((M) == SCSI_DISK0_MAJOR || \
+ ((M) >= SCSI_DISK1_MAJOR && (M) <= SCSI_DISK7_MAJOR))
+#endif /* defined(SCSI_DISK8_MAJOR) */
+#define SCSI_BLK_MAJOR(M) (SCSI_DISK_MAJOR((M)) || (M) == SCSI_CDROM_MAJOR)
+#else
+#define SCSI_BLK_MAJOR(M)  ((M) == SCSI_DISK_MAJOR || (M) == SCSI_CDROM_MAJOR)
+#endif /* defined(SCSI_DISK0_MAJOR) */
+#endif /* defined(SCSI_BLK_MAJOR) */
+ if (major == HD_MAJOR)
+ return (minor - (minor%64));
+
+ if (SCSI_BLK_MAJOR(major))
+ return (minor - (minor%16));
+ /* FIXME: Catch all */
+ return 0;
+}
+
 static errcode_t build_partition_list(struct list_head *dev_list, char *device)
 {
  errcode_t ret = 0;
@@ -329,6 +382,13 @@ static errcode_t build_partition_list(st
  dev->maj_num = major;
  dev->min_num = minor;

+ if (is_partition(major, minor)) {
+ int whole_minor = find_whole_disk_minor(major, minor);
+ list_rm_device(dev_list, major, whole_minor);
+ }
+ dev->maj_num = major;
+ dev->min_num = minor;
+
  list_add_tail(&(dev->list), dev_list);
  }



More information about the Ocfs2-tools-devel mailing list