summaryrefslogtreecommitdiff
path: root/usr/src/cmd/devfsadm/disk_link.c
diff options
context:
space:
mode:
authorJerry Jelinek <jerry.jelinek@joyent.com>2016-06-22 12:55:10 +0000
committerJerry Jelinek <jerry.jelinek@joyent.com>2016-06-22 12:55:10 +0000
commit8bae72dc3f645da905eab5fe960867037f57bae0 (patch)
tree24dce03bc58aa36ef080558a440d351c2237d4db /usr/src/cmd/devfsadm/disk_link.c
parent766f41d1d95d047e65ac4942d66037ce7f924027 (diff)
parent01aaaf328842760a1002109b299908a027e94cf8 (diff)
downloadillumos-joyent-8bae72dc3f645da905eab5fe960867037f57bae0.tar.gz
[illumos-gate merge]release-20160625
commit 01aaaf328842760a1002109b299908a027e94cf8 7051 want id_space(9F) docs commit c1de7575521deda5ee777b8054a9c5b12f15b1ee 7120 mDNS resync was not wsdiff safe commit 9c05409f2b9301e686735887a9573454cceb0331 7069 i386_XARCH should include -m32 commit 406fc5100dac8d225a315a6def6be8d628f34e24 6602 lofi should support labeled devices commit f3a07f941f1be263a48a040c059edbcb722cf436 4712 Prefer 'parsable' over 'parseable' in the manual pages commit 1b2031a95889aea96be6af55dcf31a0d5ffdfed9 7050 Prefer 'subcommand' over 'sub-command' in the manual pages commit 831b40b1c811223fd0b1131791a38e3ae5143377 7049 Prefer 'writable' over 'writeable' in the manual pages commit a716f1a92056bc2e231e57ae2a20725ce606ea73 7047 Fix spelling mistakes in sections 9E, 9F and 9S commit 95e15299a2c42b8014fa27631a6f3be2a93febc2 7048 Fix spelling mistakes in sections 7D, 7I, 7IPP, and 7P commit df23565fe1d0b225f9f898c50dfafea6749b0b7f 7046 Fix spelling mistakes in section 5 commit c855112f85cf71e42f6381a66f3f86f98e2ed24e 7045 Fix spelling mistakes in section 4 commit 843c398e8904ed9d833d2af3103894f909fb4b52 7042 Fix spelling mistakes in library sections commit 0db8de19c0e494758b68b702523a2b0eaffe3b2e 7044 Fix spelling mistakes in sections 1HAS and 2 commit df23d905b96680e56379c5a5ecb4b363f36b9e74 7041 Fix spelling mistakes in sections 1 and 1M commit 71af3be340c57171837478555e2eb0d496318cfc 7040 Detect common spelling errors in manual pages Conflicts: usr/src/uts/common/fs/vfs.c usr/src/man/man7d/cpuid.7d usr/src/man/man5/privileges.5 usr/src/man/man3c/signalfd.3c usr/src/cmd/lofiadm/main.c
Diffstat (limited to 'usr/src/cmd/devfsadm/disk_link.c')
-rw-r--r--usr/src/cmd/devfsadm/disk_link.c66
1 files changed, 59 insertions, 7 deletions
diff --git a/usr/src/cmd/devfsadm/disk_link.c b/usr/src/cmd/devfsadm/disk_link.c
index 80e75c1694..0baa608912 100644
--- a/usr/src/cmd/devfsadm/disk_link.c
+++ b/usr/src/cmd/devfsadm/disk_link.c
@@ -19,6 +19,7 @@
* CDDL HEADER END
*/
/*
+ * Copyright 2016 Toomas Soome <tsoome@me.com>
* Copyright 2012 Nexenta Systems, Inc. All rights reserved.
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
@@ -30,11 +31,13 @@
#include <stdlib.h>
#include <limits.h>
#include <ctype.h>
+#include <unistd.h>
#include <sys/int_fmtio.h>
#include <sys/stat.h>
#include <bsm/devalloc.h>
#include <sys/scsi/scsi_address.h>
#include <sys/libdevid.h>
+#include <sys/lofi.h>
#define DISK_SUBPATH_MAX 100
#define RM_STALE 0x01
@@ -69,6 +72,7 @@ static void disk_common(di_minor_t minor, di_node_t node, char *disk,
int flags);
static char *diskctrl(di_node_t node, di_minor_t minor);
static int reserved_links_exist(di_node_t node, di_minor_t minor, int nflags);
+static void disk_rm_lofi_all(char *file);
static devfsadm_create_t disk_cbt[] = {
@@ -104,9 +108,12 @@ static devfsadm_create_t disk_cbt[] = {
DEVFSADM_CREATE_INIT_V0(disk_cbt);
/*
- * HOT auto cleanup of disks not desired.
+ * HOT auto cleanup of disks is done for lofi devices only.
*/
static devfsadm_remove_t disk_remove_cbt[] = {
+ { "disk", DISK_LINK_RE, RM_HOT | RM_POST | RM_ALWAYS,
+ ILEVEL_0, disk_rm_lofi_all
+ },
{ "disk", DISK_LINK_RE, RM_POST,
ILEVEL_0, devfsadm_rm_all
}
@@ -124,6 +131,44 @@ static devlink_re_t disks_re_array[] = {
static char *disk_mid = "disk_mid";
static char *modname = "disk_link";
+/*
+ * Check if link is from lofi by checking path from readlink().
+ */
+static int
+is_lofi_disk(char *file)
+{
+ char buf[PATH_MAX + 1];
+ char filepath[PATH_MAX];
+ char *ptr;
+ ssize_t size;
+
+ size = snprintf(filepath, sizeof (filepath), "%s/dev/%s",
+ devfsadm_root_path(), file);
+ if (size > sizeof (filepath))
+ return (0);
+
+ size = readlink(filepath, buf, sizeof (buf) - 1);
+ if (size == -1)
+ return (0);
+ buf[size] = '\0';
+ ptr = strchr(buf, '@');
+ if (ptr == NULL)
+ return (0);
+ ptr[1] = '\0';
+ if (strcmp(buf, "../../devices/pseudo/lofi@") != 0)
+ return (0);
+ return (1);
+}
+
+/*
+ * Wrapper around devfsadm_rm_link() for lofi devices.
+ */
+static void disk_rm_lofi_all(char *file)
+{
+ if (is_lofi_disk(file))
+ devfsadm_rm_link(file);
+}
+
int
minor_init()
{
@@ -137,13 +182,20 @@ static int
disk_callback_chan(di_minor_t minor, di_node_t node)
{
char *addr;
- char disk[20];
- uint_t targ;
- uint_t lun;
+ char disk[23];
+ char *driver;
+ uint_t targ = 0;
+ uint_t lun = 0;
+
+ driver = di_driver_name(node);
+ if (strcmp(driver, LOFI_DRIVER_NAME) != 0) {
+ addr = di_bus_addr(node);
+ (void) sscanf(addr, "%X,%X", &targ, &lun);
+ } else {
+ targ = di_instance(node);
+ }
- addr = di_bus_addr(node);
- (void) sscanf(addr, "%X,%X", &targ, &lun);
- (void) sprintf(disk, "t%dd%d", targ, lun);
+ (void) snprintf(disk, sizeof (disk), "t%dd%d", targ, lun);
disk_common(minor, node, disk, 0);
return (DEVFSADM_CONTINUE);