udev-builtin-path_id.c revision dd8b2bf433a42683380b6fa041660dd92f91b6a9
/*
* compose persistent device path
*
* Copyright (C) 2009-2011 Kay Sievers <kay@vrfy.org>
*
* Logic based on Hannes Reinecke's shell script.
*
* 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, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#include <errno.h>
#include <dirent.h>
#include <getopt.h>
#include "udev.h"
{
char *pre;
int err = 0;
if (err < 0)
goto out;
char *new;
if (err < 0)
goto out;
} else {
}
out:
return err;
}
/*
** Linux only supports 32 bit luns.
** See drivers/scsi/scsi_scan.c::scsilun_to_int() for more details.
*/
{
/* address method 0, peripheral device addressing with bus id of zero */
if (lun < 256)
/* handle all other lun addressing methods by using a variant of the original lun format */
}
{
const char *subsystem;
break;
}
return dev;
}
{
struct udev_device *targetdev;
const char *port;
return NULL;
fcdev = udev_device_new_from_subsystem_sysname(udev, "fc_transport", udev_device_get_sysname(targetdev));
return NULL;
goto out;
}
if (lun)
out:
return parent;
}
{
struct udev_device *targetdev;
struct udev_device *target_parent;
struct udev_device *sasdev;
const char *sas_address;
return NULL;
if (target_parent == NULL)
return NULL;
return NULL;
if (sas_address == NULL) {
goto out;
}
if (lun)
out:
return parent;
}
{
struct udev_device *transportdev;
const char *target;
char *connname;
const char *addr;
const char *port;
/* find iscsi session */
for (;;) {
if (transportdev == NULL)
return NULL;
break;
}
/* find iscsi session device */
sessiondev = udev_device_new_from_subsystem_sysname(udev, "iscsi_session", udev_device_get_sysname(transportdev));
if (sessiondev == NULL)
return NULL;
goto out;
}
goto out;
}
goto out;
}
goto out;
}
if (lun)
out:
return parent;
}
{
struct udev_device *hostdev;
const char *name;
char *base;
char *pos;
int basenum;
return NULL;
return NULL;
/*
* Rebase host offset to get the local relative number
*
* Note: This is by definition racy, unreliable and too simple.
* Please do not copy this model anywhere. It's just a left-over
* from the time we had no idea how things should look like in
* the end.
*
* Making assumptions about a global in-kernel counter and use
* that to calculate a local offset is a very broken concept. It
* can only work as long as things are in strict order.
*
* controller directly, without the need for rebase magic like
* get into the way of this "I hope it works" logic.
*/
basenum = -1;
return NULL;
goto out;
}
pos[0] = '\0';
goto out;
}
char *rest;
int i;
continue;
continue;
continue;
if (rest[0] != '\0')
continue;
/*
* find the smallest number; the host really needs to export its
* own instance number per parent device; relying on the global host
* enumeration and plainly rebasing the numbers sounds unreliable
*/
basenum = i;
}
if (basenum == -1) {
goto out;
}
out:
return hostdev;
}
struct udev_device *hostdev;
struct udev_device *vmbusdev;
const char *guid_str;
char guid[38];
size_t i, k;
if (!hostdev)
return NULL;
if (!vmbusdev)
return NULL;
if (!guid_str)
return NULL;
return NULL;
for (i = 1, k = 0; i < 36; i++) {
if (guid_str[i] == '-')
continue;
}
guid[k] = '\0';
return parent;
}
{
const char *devtype;
const char *name;
const char *id;
return parent;
/* firewire */
goto out;
}
/* scsi sysfs does not have a "subsystem" for the transport */
goto out;
}
goto out;
}
goto out;
}
/*
* We do not support the ATA transport class, it uses global counters
* to name the ata devices which numbers spread across multiple
* controllers.
*
* The real link numbers are not exported. Also, possible chains of ports
* behind port multipliers cannot be composed that way.
*
* Until all that is solved at the kernel level, there are no by-path/
* links for ATA devices.
*/
goto out;
}
goto out;
}
out:
return parent;
}
{
const char *str;
unsigned int controller, disk;
return NULL;
return parent;
}
{
const char *name;
/* must be the last device in the syspath */
return;
}
{
const char *devtype;
const char *str;
const char *port;
return parent;
return parent;
return parent;
port++;
return parent;
}
static struct udev_device *handle_ccw(struct udev_device *parent, struct udev_device *dev, char **path)
{
struct udev_device *scsi_dev;
const char *wwpn;
const char *lun;
const char *hba_id;
goto out;
}
}
out:
return parent;
}
{
struct udev_device *parent;
bool some_transport = false;
/* S390 ccw bus */
goto out;
}
/* walk up the chain of devices and compose path */
const char *subsys;
;
some_transport = true;
some_transport = true;
some_transport = true;
some_transport = true;
some_transport = true;
}
}
/*
* Do not return a single-parent-device-only for block
* devices, they might have entire buses behind it which
* do not get unique IDs only by using the parent device.
*/
}
out:
char tag[UTIL_NAME_SIZE];
size_t i;
const char *p;
/* compose valid udev tag name */
for (p = path, i = 0; *p; p++) {
if ((*p >= '0' && *p <= '9') ||
(*p >= 'A' && *p <= 'Z') ||
(*p >= 'a' && *p <= 'z') ||
*p == '-') {
tag[i++] = *p;
continue;
}
/* skip all leading '_' */
if (i == 0)
continue;
/* avoid second '_' */
continue;
tag[i++] = '_';
}
/* strip trailing '_' */
i--;
tag[i] = '\0';
return EXIT_SUCCESS;
}
return EXIT_FAILURE;
}
const struct udev_builtin udev_builtin_path_id = {
.name = "path_id",
.cmd = builtin_path_id,
.help = "compose persistent device path",
.run_once = true,
};