* ioctl HDIO_GETGEO to device mapper devpath
@ 2010-10-14 9:40 Santosh Sarangi
2010-11-30 7:33 ` Hannes Reinecke
0 siblings, 1 reply; 3+ messages in thread
From: Santosh Sarangi @ 2010-10-14 9:40 UTC (permalink / raw)
To: dm-devel
[-- Attachment #1.1: Type: text/plain, Size: 1606 bytes --]
Hi,
I have a linux mapper device on the host, I would like to get the start
offset.
I get this by the following ioctl . Although the call succeeds but it sets
the hd_geometry_rec to "0"
I checked through gdb , the ioctl call suceeds ,but sets all the field of
hd_geometry to "0"
(gdb) p hd_geometry_rec
$2 = {heads = 0 '\0', sectors = 0 '\0', cylinders = 0, start = 0}
The device configuration
===================
[root@localh trunk]# uname -a
Linux localh 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:48 EDT 2009 x86_64
x86_64 x86_64 GNU/Linux
[root@localh trunk]# fdisk -l /dev/mapper/mpath4
Disk /dev/mapper/mpath4: 523 MB, 523960320 bytes
255 heads, 63 sectors/track, 63 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/mapper/mpath4p1 1 10 80293+ 83 Linux
/dev/mapper/mpath4p2 11 20 80325 83 Linux
/dev/mapper/mpath4p3 21 30 80325 83 Linux
/dev/mapper/mpath4p4 31 38 64260 83 Linux
[root@localh trunk]#
The Source code
============
struct hd_geometry hd_geometry_rec;
unsigned int offset;
// Here p_ppdevname is /dev/mapper/mpath4p4
if ((fd = open(p_ppdevname, O_RDONLY | O_NONBLOCK)) < 0)
{
//Error
}
if ((sts = ioctl(fd, HDIO_GETGEO, &hd_geometry_rec)) < 0)
{
// Error
}
else
{
offset = (unsigned int) hd_geometry_rec.start;
}
--
With best regards,
Santosh.
[-- Attachment #1.2: Type: text/html, Size: 2297 bytes --]
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: ioctl HDIO_GETGEO to device mapper devpath
2010-10-14 9:40 ioctl HDIO_GETGEO to device mapper devpath Santosh Sarangi
@ 2010-11-30 7:33 ` Hannes Reinecke
2010-12-01 8:58 ` Christophe Varoqui
0 siblings, 1 reply; 3+ messages in thread
From: Hannes Reinecke @ 2010-11-30 7:33 UTC (permalink / raw)
To: device-mapper development; +Cc: Santosh Sarangi, christophe varoqui
[-- Attachment #1: Type: text/plain, Size: 700 bytes --]
On 10/14/2010 11:40 AM, Santosh Sarangi wrote:
> Hi,
> I have a linux mapper device on the host, I would like to get the start
> offset.
> I get this by the following ioctl . Although the call succeeds but it sets
> the hd_geometry_rec to "0"
>
> I checked through gdb , the ioctl call suceeds ,but sets all the field of
> hd_geometry to "0"
>
Yep. Device-mapper device are able to report the geometry, but you
have to set it first :-)
The attached patch should fix this.
Cheers,
Hannes
--
Dr. Hannes Reinecke zSeries & Storage
hare@suse.de +49 911 74053 688
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Markus Rex, HRB 16746 (AG Nürnberg)
[-- Attachment #2: multipath-tools-set-geometry.patch --]
[-- Type: text/x-patch, Size: 4572 bytes --]
From 20122c8691d8833dbef64d21957c5e1dcce12278 Mon Sep 17 00:00:00 2001
From: Hannes Reinecke <hare@suse.de>
Date: Fri, 18 Jun 2010 12:32:21 +0200
Subject: [PATCH] Set geometry information for multipath maps
Some programs (most notably grub) try to get the device geometry
information via the HDIO_GETGEO ioctl. While device-mapper provides
this ioctl, it's values have to be set previously.
So we can just use the geometry information from the first path
to set this information for the multipath map.
Signed-off-by: Hannes Reinecke <hare@suse.de>
diff --git a/libmultipath/configure.c b/libmultipath/configure.c
index a40bef3..9530d8e 100644
--- a/libmultipath/configure.c
+++ b/libmultipath/configure.c
@@ -421,6 +421,7 @@ domap (struct multipath * mpp)
if (mpp->action != ACT_CREATE)
mpp->action = ACT_NOTHING;
}
+ dm_setgeometry(mpp);
return DOMAP_OK;
}
return DOMAP_FAIL;
diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
index fb69ee8..4a25563 100644
--- a/libmultipath/devmapper.c
+++ b/libmultipath/devmapper.c
@@ -1133,3 +1133,51 @@ out:
dm_task_destroy(dmt);
return r;
}
+
+int dm_setgeometry(struct multipath *mpp)
+{
+ struct dm_task *dmt;
+ struct path *pp;
+ char heads[4], sectors[4];
+ char cylinders[10], start[32];
+ int r = 0;
+
+ if (!mpp)
+ return 1;
+
+ pp = first_path(mpp);
+ if (!pp) {
+ condlog(3, "%s: no path for geometry", mpp->alias);
+ return 1;
+ }
+ if (pp->geom.cylinders == 0 ||
+ pp->geom.heads == 0 ||
+ pp->geom.sectors == 0) {
+ condlog(3, "%s: invalid geometry on %s", mpp->alias, pp->dev);
+ return 1;
+ }
+
+ if (!(dmt = dm_task_create(DM_DEVICE_SET_GEOMETRY)))
+ return 0;
+
+ if (!dm_task_set_name(dmt, mpp->alias))
+ goto out;
+
+ dm_task_no_open_count(dmt);
+
+ /* What a sick interface ... */
+ snprintf(heads, 4, "%u", pp->geom.heads);
+ snprintf(sectors, 4, "%u", pp->geom.sectors);
+ snprintf(cylinders, 10, "%u", pp->geom.cylinders);
+ snprintf(start, 32, "%lu", pp->geom.start);
+ if (!dm_task_set_geometry(dmt, cylinders, heads, sectors, start)) {
+ condlog(3, "%s: Failed to set geometry", mpp->alias);
+ goto out;
+ }
+
+ r = dm_task_run(dmt);
+out:
+ dm_task_destroy(dmt);
+
+ return r;
+}
diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h
index 6c22bf3..d2dd572 100644
--- a/libmultipath/devmapper.h
+++ b/libmultipath/devmapper.h
@@ -38,5 +38,6 @@ int dm_get_uuid(char *name, char *uuid);
int dm_get_info (char * mapname, struct dm_info ** dmi);
int dm_rename (char * old, char * new);
char * dm_get_name(char * uuid);
+int dm_setgeometry(struct multipath *mpp);
#endif /* _DEVMAPPER_H */
diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
index c371b47..5b04e2e 100644
--- a/libmultipath/discovery.c
+++ b/libmultipath/discovery.c
@@ -501,6 +501,23 @@ get_inq (char * dev, char * vendor, char * product, char * rev, int fd)
}
static int
+get_geometry(struct path *pp)
+{
+ if (pp->fd < 0)
+ return 1;
+
+ if (ioctl(pp->fd, HDIO_GETGEO, &pp->geom)) {
+ condlog(2, "%s: HDIO_GETGEO failed with %d", pp->dev, errno);
+ memset(&pp->geom, 0, sizeof(pp->geom));
+ return 1;
+ }
+ condlog(3, "%s: %u cyl, %u heads, %u sectors/track, start at %lu",
+ pp->dev, pp->geom.cylinders, pp->geom.heads,
+ pp->geom.sectors, pp->geom.start);
+ return 0;
+}
+
+static int
scsi_sysfs_pathinfo (struct path * pp, struct sysfs_device * parent)
{
char attr_path[FILE_NAME_SIZE];
@@ -895,6 +912,9 @@ pathinfo (struct path *pp, vector hwtable, int mask)
goto blank;
}
+ if (mask & DI_SERIAL)
+ get_geometry(pp);
+
if (pp->bus == SYSFS_BUS_SCSI &&
scsi_ioctl_pathinfo(pp, mask))
goto blank;
diff --git a/libmultipath/structs.h b/libmultipath/structs.h
index fc6413b..78ba81e 100644
--- a/libmultipath/structs.h
+++ b/libmultipath/structs.h
@@ -119,12 +119,23 @@ struct sysfs_device {
char driver[NAME_SIZE]; /* device driver name */
};
+# ifndef HDIO_GETGEO
+# define HDIO_GETGEO 0x0301 /* get device geometry */
+
+struct hd_geometry {
+ unsigned char heads;
+ unsigned char sectors;
+ unsigned short cylinders;
+ unsigned long start;
+};
+#endif
struct path {
char dev[FILE_NAME_SIZE];
char dev_t[BLK_DEV_SIZE];
struct sysfs_device *sysdev;
struct scsi_idlun scsi_id;
struct sg_id sg_id;
+ struct hd_geometry geom;
char wwid[WWID_SIZE];
char vendor_id[SCSI_VENDOR_SIZE];
char product_id[SCSI_PRODUCT_SIZE];
@@ -146,7 +157,7 @@ struct path {
struct checker checker;
struct multipath * mpp;
int fd;
-
+
/* configlet pointers */
struct hwentry * hwe;
};
[-- Attachment #3: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: ioctl HDIO_GETGEO to device mapper devpath
2010-11-30 7:33 ` Hannes Reinecke
@ 2010-12-01 8:58 ` Christophe Varoqui
0 siblings, 0 replies; 3+ messages in thread
From: Christophe Varoqui @ 2010-12-01 8:58 UTC (permalink / raw)
To: device-mapper development
On mar., 2010-11-30 at 08:33 +0100, Hannes Reinecke wrote:
> On 10/14/2010 11:40 AM, Santosh Sarangi wrote:
> > Hi,
> > I have a linux mapper device on the host, I would like to get the start
> > offset.
> > I get this by the following ioctl . Although the call succeeds but it sets
> > the hd_geometry_rec to "0"
> >
> > I checked through gdb , the ioctl call suceeds ,but sets all the field of
> > hd_geometry to "0"
> >
> Yep. Device-mapper device are able to report the geometry, but you
> have to set it first :-)
>
> The attached patch should fix this.
>
Applied.
Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-12-01 8:58 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-14 9:40 ioctl HDIO_GETGEO to device mapper devpath Santosh Sarangi
2010-11-30 7:33 ` Hannes Reinecke
2010-12-01 8:58 ` Christophe Varoqui
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).