[parted-devel] [PATCH] Correctly name virtio devices.
Joel Granados Moreno
jgranado at redhat.com
Tue Mar 31 13:27:44 UTC 2009
* include/parted/device.h (PedDeviceType): Add a new PED_DEVICE_VIRTBLK
type to the list.
* libparted/arch/linux.c (_is_dm_major): Modify this function so it
calls the new _is_major_type function with type "device-mapper".
* libparted/arch/linux.c (_is_major_type): Searches a major number
inside /proc/devices based on a "type" string.
* libparted/arch/linux.c (_is_virtblk_major): New function. Calls
_is_major_type with type "virtblk".
* libparted/arch/linux.c (_device_probe_type): Add a new
PED_DEVICE_VIRTBLK case to the probe possibilities.
* libparted/arch/linux.c (linux_new): Add a new PED_DEVICE_VIRTBLK case
to the possible device types.
* parted/parted.c (do_print): add the "virtblk" string to the transport
array.
---
include/parted/device.h | 3 +-
libparted/arch/linux.c | 101 ++++++++++++++++++++++++++++-------------------
parted/parted.c | 2 +-
3 files changed, 63 insertions(+), 43 deletions(-)
diff --git a/include/parted/device.h b/include/parted/device.h
index 5636ce8..151305f 100644
--- a/include/parted/device.h
+++ b/include/parted/device.h
@@ -45,7 +45,8 @@ typedef enum {
PED_DEVICE_SX8 = 11,
PED_DEVICE_DM = 12,
PED_DEVICE_XVD = 13,
- PED_DEVICE_SDMMC = 14
+ PED_DEVICE_SDMMC = 14,
+ PED_DEVICE_VIRTBLK = 15
} PedDeviceType;
typedef struct _PedDevice PedDevice;
diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
index 6e47107..6a4818e 100644
--- a/libparted/arch/linux.c
+++ b/libparted/arch/linux.c
@@ -322,45 +322,6 @@ _is_sx8_major (int major)
return (SX8_MAJOR1 <= major && major <= SX8_MAJOR2);
}
-#ifdef ENABLE_DEVICE_MAPPER
-static int
-_dm_maptype (PedDevice *dev)
-{
- LinuxSpecific* arch_specific = LINUX_SPECIFIC (dev);
- struct dm_task *dmt;
- void *next;
- uint64_t start, length;
- char *target_type = NULL;
- char *params;
- int r = -1;
- const char* dev_dir = getenv ("DM_DEV_DIR");
-
- if (dev_dir && *dev_dir && !dm_set_dev_dir(dev_dir))
- return r;
-
- if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
- return r;
-
- if (!dm_task_set_name(dmt, dev->path))
- goto bad;
-
- dm_task_no_open_count(dmt);
-
- if (!dm_task_run(dmt))
- goto bad;
-
- next = dm_get_next_target(dmt, NULL, &start, &length,
- &target_type, ¶ms);
-
- arch_specific->dmtype = strdup(target_type ? target_type : "NO-TARGET");
- if (arch_specific->dmtype == NULL)
- goto bad;
- r = 0;
-bad:
- dm_task_destroy(dmt);
- return r;
-}
-
static int
readFD (int fd, char **buf)
{
@@ -398,7 +359,7 @@ readFD (int fd, char **buf)
}
static int
-_is_dm_major (int major)
+_is_major_type (int major, const char* type)
{
int fd;
char* buf = NULL;
@@ -432,7 +393,7 @@ _is_dm_major (int major)
}
name = strrchr(line, ' ');
- if (!name || strcmp(name+1, "device-mapper"))
+ if (!name || strcmp(name+1, type))
goto next;
maj = strtol(line, &name, 10);
@@ -453,6 +414,58 @@ next:
}
static int
+_is_virtblk_major (int major)
+{
+ return _is_major_type (major, "virtblk");
+}
+
+#ifdef ENABLE_DEVICE_MAPPER
+static int
+_is_dm_major (int major)
+{
+ return _is_major_type (major, "device-mapper");
+}
+
+static int
+_dm_maptype (PedDevice *dev)
+{
+ LinuxSpecific* arch_specific = LINUX_SPECIFIC (dev);
+ struct dm_task *dmt;
+ void *next;
+ uint64_t start, length;
+ char *target_type = NULL;
+ char *params;
+ int r = -1;
+ const char* dev_dir = getenv ("DM_DEV_DIR");
+
+ if (dev_dir && *dev_dir && !dm_set_dev_dir(dev_dir))
+ return r;
+
+ if (!(dmt = dm_task_create(DM_DEVICE_TABLE)))
+ return r;
+
+ if (!dm_task_set_name(dmt, dev->path))
+ goto bad;
+
+ dm_task_no_open_count(dmt);
+
+ if (!dm_task_run(dmt))
+ goto bad;
+
+ next = dm_get_next_target(dmt, NULL, &start, &length,
+ &target_type, ¶ms);
+
+ arch_specific->dmtype = strdup(target_type ? target_type : "NO-TARGET");
+ if (arch_specific->dmtype == NULL)
+ goto bad;
+ r = 0;
+bad:
+ dm_task_destroy(dmt);
+ return r;
+}
+
+
+static int
_probe_dm_devices ()
{
DIR* mapper_dir;
@@ -561,6 +574,8 @@ _device_probe_type (PedDevice* dev)
dev->type = PED_DEVICE_XVD;
} else if (dev_major == SDMMC_MAJOR && (dev_minor % 0x08 == 0)) {
dev->type = PED_DEVICE_SDMMC;
+ } else if (_is_virtblk_major(dev_major)) {
+ dev->type = PED_DEVICE_VIRTBLK;
} else {
dev->type = PED_DEVICE_UNKNOWN;
}
@@ -1315,6 +1330,10 @@ linux_new (const char* path)
if (!init_sdmmc (dev))
goto error_free_arch_specific;
break;
+ case PED_DEVICE_VIRTBLK:
+ if (!init_generic(dev, _("Virtio Block Device")))
+ goto error_free_arch_specific;
+ break;
default:
ped_exception_throw (PED_EXCEPTION_NO_FEATURE,
diff --git a/parted/parted.c b/parted/parted.c
index 5f2f2aa..ac1b176 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -1271,7 +1271,7 @@ do_print (PedDevice** dev)
const char *const transport[] = {"unknown", "scsi", "ide", "dac960",
"cpqarray", "file", "ataraid", "i2o",
"ubd", "dasd", "viodasd", "sx8", "dm",
- "xvd", "sd/mmc"};
+ "xvd", "sd/mmc", "virtblk"};
char* peek_word;
char* start;
char* end;
--
1.6.0.6
More information about the parted-devel
mailing list