sys/dev/disk/dm: Cleanup DIOCGPART related code
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Mon, 12 Oct 2015 02:00:10 +0000 (11:00 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Wed, 14 Oct 2015 19:06:15 +0000 (04:06 +0900)
sys/dev/disk/dm/device-mapper.c
sys/dev/disk/dm/dm_pdev.c

index 1aebd6b..de6bea5 100644 (file)
@@ -303,7 +303,6 @@ dm_ioctl_switch(u_long cmd)
 {
 
        switch(cmd) {
-
        case NETBSD_DM_IOCTL:
                aprint_debug("dm NETBSD_DM_IOCTL called\n");
                break;
@@ -331,17 +330,15 @@ disk_ioctl_switch(cdev_t dev, u_long cmd, void *data)
 
        switch(cmd) {
        case DIOCGPART:
-       {
-               struct partinfo *dpart;
-               u_int64_t size;
-               dpart = data;
-               bzero(dpart, sizeof(*dpart));
-
                if ((dmv = dev->si_drv1) == NULL)
                        return ENODEV;
                if (dmv->diskp->d_info.d_media_blksize == 0) {
                        return ENOTSUP;
                } else {
+                       u_int64_t size;
+                       struct partinfo *dpart = data;
+                       bzero(dpart, sizeof(*dpart));
+
                        size = dm_table_size(&dmv->table_head);
                        dpart->media_offset  = 0;
                        dpart->media_size    = size * DEV_BSIZE;
@@ -350,7 +347,6 @@ disk_ioctl_switch(cdev_t dev, u_long cmd, void *data)
                        dpart->fstype = FS_BSDFFS;
                }
                break;
-       }
 
        default:
                aprint_debug("unknown disk_ioctl called\n");
index 2c80625..929796a 100644 (file)
@@ -157,6 +157,17 @@ dm_pdev_insert(const char *dev_name)
        bzero(&dmp->pdev_pinfo, sizeof(dmp->pdev_pinfo));
        error = dev_dioctl(dmp->pdev_vnode->v_rdev, DIOCGPART,
            (void *)&dmp->pdev_pinfo, 0, proc0.p_ucred, NULL, NULL);
+       if (!error) {
+               struct partinfo *dpart = &dmp->pdev_pinfo;
+               aprint_debug("dmp_pdev_insert DIOCGPART "
+                       "offset=%ju size=%ju blocks=%ju blksize=%d\n",
+                       dpart->media_offset,
+                       dpart->media_size,
+                       dpart->media_blocks,
+                       dpart->media_blksize);
+       } else {
+               aprint_normal("dmp_pdev_insert DIOCGPART failed %d\n", error);
+       }
 
        lockmgr(&dm_pdev_mutex, LK_EXCLUSIVE);
        SLIST_INSERT_HEAD(&dm_pdev_list, dmp, next_pdev);