From: Matt Domsch <Matt_Domsch@dell.com>
To: linux-scsi@vger.kernel.org, linux-hotplug-devel@lists.sourceforge.net
Subject: [RFC][PATCH 2.6.11-rc2] Linux SCSI hotplug infrastructure
Date: Mon, 07 Feb 2005 18:27:53 +0000 [thread overview]
Message-ID: <20050207182753.GA16526@lists.us.dell.com> (raw)
Below is a patch to add some hotplug infrastructure to the Linux SCSI
subsystem.
New files:
include/scsi/scsi_hotplug.h
drivers/scsi/scsi_hotplug.c
implements a new exported function:
extern int scsi_topology_hctl_action(struct Scsi_Host *shost, unsigned int channel,
unsigned int id, unsigned int lun, enum scsi_topology_action action);
which invokes kobject_hotplug() on a temporary "scsi_topology"
device. This device represents a target that exists on a topology
(i.e. was just inserted into a hot plug enclosure, or was just created
by a RAID controller management application) but is not yet hooked
into the kernel.
Modified files:
drivers/scsi/Kconfig
drivers/scsi/Makefile
drivers/scsi/megaraid/megaraid_mbox.c
(will follow in a separate patch)
is the user of this new function.
In addition, two more infrastructure pieces are necessary:
udev-050-scsi_topology.patch - adds the subsystem name "scsi_topology"
to the list of devices *not* to wait for the creation of files in
sysfs for - scsi_topology devices aren't to be registered in sysfs.
/etc/hotplug/scsi_topology.agent
handles the hotplug call, and invokes /sys/class/scsi_host/hostX/scan
and /sys/class/scsi_device/H:C:T:L:/device/delete as appropriate.
The flow is as follows:
# echo "2" > /sys/class/scsi_host/host2/logical_drive_created
(to be done by a management application that knows it just created
logical drive #2 on the controller)
megaraid_mbox.c sysfs method converts logical drive number to HCTL
value, calls scsi_topology_hctl_action().
scsi_topology_hctl_action() invokes kobject_hotplug() with a
scsi_topology subsystem device.
kobject_hotplug() calls /sbin/hotplug or /sbin/udevsend (more likely
the latter), which invokes /etc/hotplug/scsi_topology.agent with the
ACTION={add,remove}.
scsi_topology.agent invokes /sys/class/scsi_host/hostX/scan or
/sys/class/scsi_device/H:C:T:L:/device/delete as appropriate.
From this point, we're back into known territory, with the device
being made known, or deleted from, the kernel's view.
Thoughts?
Signed-off-by: Matt Domsch <Matt_Domsch@dell.com>
--
Matt Domsch
Software Architect
Dell Linux Solutions linux.dell.com & www.dell.com/linux
Linux on Dell mailing lists @ http://lists.us.dell.com
=== drivers/scsi/Kconfig 1.95 vs edited ==--- 1.95/drivers/scsi/Kconfig 2005-01-28 11:14:29 -06:00
+++ edited/drivers/scsi/Kconfig 2005-02-05 13:58:45 -06:00
@@ -185,6 +185,16 @@
there should be no noticeable performance impact as long as you have
logging turned off.
+config SCSI_HOTPLUG
+ bool "Hot Plug SCSI devices"
+ depends on SCSI && EXPERIMENTAL
+ default y
+ help
+ If your driver or management applications know about
+ device hot plugging (insertion/removal of physical disks in
+ a topology, or creation/deletion of logical disks on a RAID
+ controller), say Y here. Otherwise, say N.
+
menu "SCSI Transport Attributes"
depends on SCSI
=== drivers/scsi/Makefile 1.72 vs edited ==--- 1.72/drivers/scsi/Makefile 2004-11-20 14:26:17 -06:00
+++ edited/drivers/scsi/Makefile 2005-02-05 13:58:15 -06:00
@@ -147,6 +147,7 @@
scsi_devinfo.o
scsi_mod-$(CONFIG_SYSCTL) += scsi_sysctl.o
scsi_mod-$(CONFIG_SCSI_PROC_FS) += scsi_proc.o
+scsi_mod-$(CONFIG_SCSI_HOTPLUG) += scsi_hotplug.o
sd_mod-objs := sd.o
sr_mod-objs := sr.o sr_ioctl.o sr_vendor.o
--- /dev/null Thu Apr 11 09:25:15 2002
+++ include/scsi/scsi_hotplug.h Sun Feb 6 23:29:51 2005
@@ -0,0 +1,41 @@
+/*
+ * SCSI Hotplug
+ *
+ * Copyright (c) 2005 Dell, Inc <Matt_Domsch@dell.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef _SCSI_SCSI_HOTPLUG_H
+#define _SCSI_SCSI_HOTPLUG_H
+
+#include <linux/config.h>
+#include <scsi/scsi_host.h>
+#include <scsi/scsi_device.h>
+
+enum scsi_topology_action {
+ SCSI_TOPOLOGY_ADDED = 1, /* device added in the topology */
+ SCSI_TOPOLOGY_REMOVED = 2, /* device removed from the topology */
+};
+
+#if defined (CONFIG_SCSI_HOTPLUG) || defined(CONFIG_SCSI_HOTPLUG_MODULE)
+extern int scsi_topology_hctl_action(struct Scsi_Host *shost, unsigned int channel,
+ unsigned int id, unsigned int lun, enum scsi_topology_action action);
+#else
+static inline int scsi_topology_hctl_action(struct Scsi_Host *shost, unsigned int channel,
+ unsigned int id, unsigned int lun, enum scsi_topology_action action)
+{return -ENOSYS;}
+#endif
+
+#endif /* _SCSI_SCSI_HOTPLUG_H */
--- /dev/null Thu Apr 11 09:25:15 2002
+++ drivers/scsi/scsi_hotplug.c Sun Feb 6 23:42:21 2005
@@ -0,0 +1,138 @@
+/*
+ * SCSI Hotplug
+ *
+ * Copyright (c) 2005 Dell, Inc <Matt_Domsch@dell.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/kobject.h>
+#include <scsi/scsi_hotplug.h>
+
+/*
+ * TODO:
+ * - if CONFIG_SCSI_HOTPLUG=y and CONFIG_SCSI=y, then the exported
+ * functions here get dropped by the vmlinux linker, as there are no
+ * vmlinux users of them (only modules).
+ *
+ */
+
+/* This belongs in include/device.h, as drivers/base/core.c defines it too */
+#define to_dev(obj) container_of(obj, struct device, kobj)
+
+static int scsi_topology_device_hotplug(struct kset *kset, struct kobject *kobj, char **envp,
+ int num_envp, char *buffer, int buffer_size)
+{
+
+ struct device *dev = to_dev(kobj);
+ struct device *parent_dev = dev->parent;
+ struct scsi_device *sdev = to_scsi_device(dev);
+ struct Scsi_Host *shost = dev_to_shost(parent_dev);
+ int length = 0;
+ int i = 0;
+
+ add_hotplug_env_var(envp, num_envp, &i, buffer, buffer_size, &length,
+ "SCSI_TOPOLOGY_EVENT=1");
+ add_hotplug_env_var(envp, num_envp, &i, buffer, buffer_size, &length,
+ "SCSI_TOPOLOGY_EVENT_HCTL=1");
+ add_hotplug_env_var(envp, num_envp, &i, buffer, buffer_size, &length,
+ "SCSI_HOST=%u", shost->host_no);
+ add_hotplug_env_var(envp, num_envp, &i, buffer, buffer_size, &length,
+ "SCSI_CHANNEL=%u", sdev->channel);
+ add_hotplug_env_var(envp, num_envp, &i, buffer, buffer_size, &length,
+ "SCSI_ID=%u", sdev->id);
+ add_hotplug_env_var(envp, num_envp, &i, buffer, buffer_size, &length,
+ "SCSI_LUN=%u", sdev->lun);
+
+ envp[i] = NULL;
+ return 0;
+}
+
+static struct kset_hotplug_ops scsi_topology_device_kset_ops +{
+ .hotplug = scsi_topology_device_hotplug,
+};
+
+static struct kset scsi_topology_device_kset = {
+ .hotplug_ops = &scsi_topology_device_kset_ops,
+ .kobj = {
+ .name = "scsi_topology",
+ },
+};
+
+static void scsi_topology_device_release(struct device *dev)
+{
+ put_device(dev->parent);
+}
+
+static int scsi_topology_device_init(struct scsi_device *sdev,
+ struct Scsi_Host *shost,
+ unsigned int channel,
+ unsigned int id,
+ unsigned int lun)
+{
+ struct device *dev;
+ memset(sdev, 0, sizeof(*sdev));
+ dev = &sdev->sdev_gendev;
+ snprintf(dev->bus_id, BUS_ID_SIZE, "topology-%u:%u:%u:%u",
+ shost->host_no, channel, id, lun);
+ dev->parent = get_device(&shost->shost_gendev);
+ dev->release = scsi_topology_device_release;
+ sdev->channel = channel;
+ sdev->id = id;
+ sdev->lun = lun;
+ device_initialize(dev);
+ kobject_set_name(&dev->kobj, "%s", dev->bus_id);
+ dev->kobj.parent = &dev->parent->kobj;
+ dev->kobj.kset = &scsi_topology_device_kset;
+ return 0;
+}
+
+static inline enum kobject_action scsi_topology_action_to_kobject_action(enum scsi_topology_action action)
+{
+ enum kobject_action kaction = KOBJ_CHANGE; /* should there be a KOBJ_NOOP? */
+ switch (action) {
+ case SCSI_TOPOLOGY_ADDED:
+ kaction = KOBJ_ADD;
+ break;
+ case SCSI_TOPOLOGY_REMOVED:
+ kaction = KOBJ_REMOVE;
+ break;
+ }
+ return kaction;
+}
+
+
+int scsi_topology_hctl_action(struct Scsi_Host *shost, unsigned int channel,
+ unsigned int id, unsigned int lun, enum scsi_topology_action action)
+{
+ struct scsi_device *sdev;
+ enum kobject_action kaction;
+ int error;
+
+ sdev = kmalloc(sizeof(*sdev), GFP_KERNEL);
+ if (!sdev)
+ return -ENOMEM;
+ error = scsi_topology_device_init(sdev, shost, channel, id, lun);
+ if (error)
+ return error;
+ kaction = scsi_topology_action_to_kobject_action(action);
+ kobject_hotplug(&sdev->sdev_gendev.kobj, kaction);
+ kfree(sdev);
+ return 0;
+}
+EXPORT_SYMBOL_GPL(scsi_topology_hctl_action);
-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_ide95&alloc_id\x14396&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel
next reply other threads:[~2005-02-07 18:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-02-07 18:27 Matt Domsch [this message]
2005-02-07 18:29 ` [RFC][PATCH 2.6.11-rc2] Linux SCSI hotplug infrastructure Matt Domsch
2005-02-07 18:29 ` Matt Domsch
2005-02-07 18:30 ` Matt Domsch
2005-02-07 19:22 ` Brian King
2005-02-07 19:40 ` Matt Domsch
2005-02-08 23:19 ` Matt Domsch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050207182753.GA16526@lists.us.dell.com \
--to=matt_domsch@dell.com \
--cc=linux-hotplug-devel@lists.sourceforge.net \
--cc=linux-scsi@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).