summaryrefslogtreecommitdiffstats
path: root/sys/geom
diff options
context:
space:
mode:
authorgibbs <gibbs@FreeBSD.org>2011-06-14 17:10:32 +0000
committergibbs <gibbs@FreeBSD.org>2011-06-14 17:10:32 +0000
commit094b6aca1decaa03a1efdb6361ca6d7d1d3cc4d3 (patch)
tree2ba93494158658cf752e99e3930ef38a4872311c /sys/geom
parentf797e31a8d7ffc81bda219abef89c378821566db (diff)
downloadFreeBSD-src-094b6aca1decaa03a1efdb6361ca6d7d1d3cc4d3.zip
FreeBSD-src-094b6aca1decaa03a1efdb6361ca6d7d1d3cc4d3.tar.gz
Plumb device physical path reporting from CAM devices, through GEOM and
DEVFS, and make it accessible via the diskinfo utility. Extend GEOM's generic attribute query mechanism into generic disk consumers. sys/geom/geom_disk.c: sys/geom/geom_disk.h: sys/cam/scsi/scsi_da.c: sys/cam/ata/ata_da.c: - Allow disk providers to implement a new method which can override the default BIO_GETATTR response, d_getattr(struct bio *). This function returns -1 if not handled, otherwise it returns 0 or an errno to be passed to g_io_deliver(). sys/cam/scsi/scsi_da.c: sys/cam/ata/ata_da.c: - Don't copy the serial number to dp->d_ident anymore, as the CAM XPT is now responsible for returning this information via d_getattr()->(a)dagetattr()->xpt_getatr(). sys/geom/geom_dev.c: - Implement a new ioctl, DIOCGPHYSPATH, which returns the GEOM attribute "GEOM::physpath", if possible. If the attribute request returns a zero-length string, ENOENT is returned. usr.sbin/diskinfo/diskinfo.c: - If the DIOCGPHYSPATH ioctl is successful, report physical path data when diskinfo is executed with the '-v' option. Submitted by: will Reviewed by: gibbs Sponsored by: Spectra Logic Corporation Add generic attribute change notification support to GEOM. sys/sys/geom/geom.h: Add a new attrchanged method field to both g_class and g_geom. sys/sys/geom/geom.h: sys/geom/geom_event.c: - Provide the g_attr_changed() function that providers can use to advertise attribute changes. - Perform delivery of attribute change notifications from a thread context via the standard GEOM event mechanism. sys/geom/geom_subr.c: Inherit the attrchanged method from class to geom (class instance). sys/geom/geom_disk.c: Provide disk_attr_changed() to provide g_attr_changed() access to consumers of the disk API. sys/cam/scsi/scsi_pass.c: sys/cam/scsi/scsi_da.c: sys/geom/geom_dev.c: sys/geom/geom_disk.c: Use attribute changed events to track updates to physical path information. sys/cam/scsi/scsi_da.c: Add AC_ADVINFO_CHANGED to the registered asynchronous CAM events for this driver. When this event occurs, and the updated buffer type references our physical path attribute, emit a GEOM attribute changed event via the disk_attr_changed() API. sys/cam/scsi/scsi_pass.c: Add AC_ADVINFO_CHANGED to the registered asynchronous CAM events for this driver. When this event occurs, update the physical patch devfs alias for this pass instance. Submitted by: gibbs Sponsored by: Spectra Logic Corporation
Diffstat (limited to 'sys/geom')
-rw-r--r--sys/geom/geom.h5
-rw-r--r--sys/geom/geom_dev.c52
-rw-r--r--sys/geom/geom_disk.c21
-rw-r--r--sys/geom/geom_disk.h3
-rw-r--r--sys/geom/geom_event.c47
-rw-r--r--sys/geom/geom_subr.c1
6 files changed, 128 insertions, 1 deletions
diff --git a/sys/geom/geom.h b/sys/geom/geom.h
index 1dc6eb1..6256572 100644
--- a/sys/geom/geom.h
+++ b/sys/geom/geom.h
@@ -76,6 +76,7 @@ typedef void g_orphan_t (struct g_consumer *);
typedef void g_start_t (struct bio *);
typedef void g_spoiled_t (struct g_consumer *);
+typedef void g_attrchanged_t (struct g_consumer *, const char *attr);
typedef void g_dumpconf_t (struct sbuf *, const char *indent, struct g_geom *,
struct g_consumer *, struct g_provider *);
@@ -100,6 +101,7 @@ struct g_class {
*/
g_start_t *start;
g_spoiled_t *spoiled;
+ g_attrchanged_t *attrchanged;
g_dumpconf_t *dumpconf;
g_access_t *access;
g_orphan_t *orphan;
@@ -128,6 +130,7 @@ struct g_geom {
int rank;
g_start_t *start;
g_spoiled_t *spoiled;
+ g_attrchanged_t *attrchanged;
g_dumpconf_t *dumpconf;
g_access_t *access;
g_orphan_t *orphan;
@@ -217,6 +220,7 @@ struct g_classifier_hook {
/* geom_dev.c */
struct cdev;
void g_dev_print(void);
+void g_dev_physpath_changed(void);
struct g_provider *g_dev_getprovider(struct cdev *dev);
/* geom_dump.c */
@@ -232,6 +236,7 @@ typedef void g_event_t(void *, int flag);
int g_post_event(g_event_t *func, void *arg, int flag, ...);
int g_waitfor_event(g_event_t *func, void *arg, int flag, ...);
void g_cancel_event(void *ref);
+int g_attr_changed(struct g_provider *pp, const char *attr, int flag);
void g_orphan_provider(struct g_provider *pp, int error);
void g_waitidlelock(void);
diff --git a/sys/geom/geom_dev.c b/sys/geom/geom_dev.c
index f291b32..210f2ee 100644
--- a/sys/geom/geom_dev.c
+++ b/sys/geom/geom_dev.c
@@ -41,6 +41,7 @@ __FBSDID("$FreeBSD$");
#include <sys/malloc.h>
#include <sys/kernel.h>
#include <sys/conf.h>
+#include <sys/ctype.h>
#include <sys/bio.h>
#include <sys/lock.h>
#include <sys/mutex.h>
@@ -52,6 +53,12 @@ __FBSDID("$FreeBSD$");
#include <sys/limits.h>
#include <geom/geom.h>
#include <geom/geom_int.h>
+#include <machine/stdarg.h>
+
+/*
+ * Use the consumer private field to reference a physdev alias (if any).
+ */
+#define cp_alias_dev private
static d_open_t g_dev_open;
static d_close_t g_dev_close;
@@ -72,12 +79,14 @@ static struct cdevsw g_dev_cdevsw = {
static g_taste_t g_dev_taste;
static g_orphan_t g_dev_orphan;
+static g_attrchanged_t g_dev_attrchanged;
static struct g_class g_dev_class = {
.name = "DEV",
.version = G_VERSION,
.taste = g_dev_taste,
.orphan = g_dev_orphan,
+ .attrchanged = g_dev_attrchanged
};
void
@@ -93,6 +102,40 @@ g_dev_print(void)
printf("\n");
}
+static void
+g_dev_attrchanged(struct g_consumer *cp, const char *attr)
+{
+
+ if (strcmp(attr, "GEOM::physpath") != 0)
+ return;
+
+ if (g_access(cp, 1, 0, 0) == 0) {
+ char *physpath;
+ int error, physpath_len;
+
+ physpath_len = MAXPATHLEN;
+ physpath = g_malloc(physpath_len, M_WAITOK|M_ZERO);
+ error =
+ g_io_getattr("GEOM::physpath", cp, &physpath_len, physpath);
+ g_access(cp, -1, 0, 0);
+ if (error == 0 && strlen(physpath) != 0) {
+ struct cdev *dev;
+ struct cdev *old_alias_dev;
+ struct cdev **alias_devp;
+
+ dev = cp->geom->softc;
+ old_alias_dev = cp->cp_alias_dev;
+ alias_devp = (struct cdev **)&cp->cp_alias_dev;
+ make_dev_physpath_alias(MAKEDEV_WAITOK, alias_devp,
+ dev, old_alias_dev, physpath);
+ } else if (cp->cp_alias_dev) {
+ destroy_dev((struct cdev *)cp->cp_alias_dev);
+ cp->cp_alias_dev = NULL;
+ }
+ g_free(physpath);
+ }
+}
+
struct g_provider *
g_dev_getprovider(struct cdev *dev)
{
@@ -107,7 +150,6 @@ g_dev_getprovider(struct cdev *dev)
return (cp->provider);
}
-
static struct g_geom *
g_dev_taste(struct g_class *mp, struct g_provider *pp, int insist __unused)
{
@@ -167,6 +209,9 @@ g_dev_taste(struct g_class *mp, struct g_provider *pp, int insist __unused)
adev->si_drv1 = gp;
adev->si_drv2 = cp;
}
+
+ g_dev_attrchanged(cp, "GEOM::physpath");
+
return (gp);
}
@@ -365,6 +410,11 @@ g_dev_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag, struct thread
case DIOCGSTRIPEOFFSET:
*(off_t *)data = cp->provider->stripeoffset;
break;
+ case DIOCGPHYSPATH:
+ error = g_io_getattr("GEOM::physpath", cp, &i, data);
+ if (error == 0 && *(char *)data == '\0')
+ error = ENOENT;
+ break;
default:
if (cp->provider->geom->ioctl != NULL) {
error = cp->provider->geom->ioctl(cp->provider, cmd, data, fflag, td);
diff --git a/sys/geom/geom_disk.c b/sys/geom/geom_disk.c
index e663e3d..17cae68 100644
--- a/sys/geom/geom_disk.c
+++ b/sys/geom/geom_disk.c
@@ -347,6 +347,15 @@ g_disk_start(struct bio *bp)
} while (bp2 != NULL);
break;
case BIO_GETATTR:
+ /* Give the driver a chance to override */
+ if (dp->d_getattr != NULL) {
+ if (bp->bio_disk == NULL)
+ bp->bio_disk = dp;
+ error = dp->d_getattr(bp);
+ if (error != -1)
+ break;
+ error = EJUSTRETURN;
+ }
if (g_handleattr_int(bp, "GEOM::candelete",
(dp->d_flags & DISKFLAG_CANDELETE) != 0))
break;
@@ -582,6 +591,18 @@ disk_gone(struct disk *dp)
g_wither_provider(pp, ENXIO);
}
+void
+disk_attr_changed(struct disk *dp, const char *attr, int flag)
+{
+ struct g_geom *gp;
+ struct g_provider *pp;
+
+ gp = dp->d_geom;
+ if (gp != NULL)
+ LIST_FOREACH(pp, &gp->provider, provider)
+ (void)g_attr_changed(pp, attr, flag);
+}
+
static void
g_kern_disks(void *p, int flag __unused)
{
diff --git a/sys/geom/geom_disk.h b/sys/geom/geom_disk.h
index 2d5f15d..e92f4aa 100644
--- a/sys/geom/geom_disk.h
+++ b/sys/geom/geom_disk.h
@@ -49,6 +49,7 @@ struct disk;
typedef int disk_open_t(struct disk *);
typedef int disk_close_t(struct disk *);
typedef void disk_strategy_t(struct bio *bp);
+typedef int disk_getattr_t(struct bio *bp);
typedef int disk_ioctl_t(struct disk *, u_long cmd, void *data,
int fflag, struct thread *td);
/* NB: disk_ioctl_t SHALL be cast'able to d_ioctl_t */
@@ -75,6 +76,7 @@ struct disk {
disk_strategy_t *d_strategy;
disk_ioctl_t *d_ioctl;
dumper_t *d_dump;
+ disk_getattr_t *d_getattr;
/* Info fields from driver to geom_disk.c. Valid when open */
u_int d_sectorsize;
@@ -104,6 +106,7 @@ struct disk *disk_alloc(void);
void disk_create(struct disk *disk, int version);
void disk_destroy(struct disk *disk);
void disk_gone(struct disk *disk);
+void disk_attr_changed(struct disk *dp, const char *attr, int flag);
#define DISK_VERSION_00 0x58561059
#define DISK_VERSION_01 0x5856105a
diff --git a/sys/geom/geom_event.c b/sys/geom/geom_event.c
index d6e5498..1e2fc8d 100644
--- a/sys/geom/geom_event.c
+++ b/sys/geom/geom_event.c
@@ -110,6 +110,53 @@ g_waitidlelock(void)
}
#endif
+struct g_attrchanged_args {
+ struct g_provider *pp;
+ const char *attr;
+};
+
+static void
+g_attr_changed_event(void *arg, int flag)
+{
+ struct g_attrchanged_args *args;
+ struct g_provider *pp;
+ struct g_consumer *cp;
+ struct g_consumer *next_cp;
+
+ args = arg;
+ pp = args->pp;
+
+ g_topology_assert();
+ if (flag != EV_CANCEL && g_shutdown == 0) {
+
+ /*
+ * Tell all consumers of the change.
+ */
+ LIST_FOREACH_SAFE(cp, &pp->consumers, consumers, next_cp) {
+ if (cp->geom->attrchanged != NULL)
+ cp->geom->attrchanged(cp, args->attr);
+ }
+ }
+ g_free(args);
+}
+
+int
+g_attr_changed(struct g_provider *pp, const char *attr, int flag)
+{
+ struct g_attrchanged_args *args;
+ int error;
+
+ args = g_malloc(sizeof *args, flag);
+ if (args == NULL)
+ return (ENOMEM);
+ args->pp = pp;
+ args->attr = attr;
+ error = g_post_event(g_attr_changed_event, args, flag, pp, NULL);
+ if (error != 0)
+ g_free(args);
+ return (error);
+}
+
void
g_orphan_provider(struct g_provider *pp, int error)
{
diff --git a/sys/geom/geom_subr.c b/sys/geom/geom_subr.c
index a0958f3..6e2589b 100644
--- a/sys/geom/geom_subr.c
+++ b/sys/geom/geom_subr.c
@@ -350,6 +350,7 @@ g_new_geomf(struct g_class *mp, const char *fmt, ...)
/* Fill in defaults from class */
gp->start = mp->start;
gp->spoiled = mp->spoiled;
+ gp->attrchanged = mp->attrchanged;
gp->dumpconf = mp->dumpconf;
gp->access = mp->access;
gp->orphan = mp->orphan;
OpenPOWER on IntegriCloud