diff --git a/zfs/lib/libspl/kernel.c b/zfs/lib/libspl/kernel.c index 4bdfd9766b..ad2e0ff0fe 100644 --- a/zfs/lib/libspl/kernel.c +++ b/zfs/lib/libspl/kernel.c @@ -400,7 +400,11 @@ vn_open(char *path, int x1, int flags, int mode, vnode_t **vpp, int x2, int x3) * for its size. So -- gag -- we open the block device to get * its size, and remember it for subsequent VOP_GETATTR(). */ +#if defined(__sun__) || defined(__sun) if (strncmp(path, "/dev/", 5) == 0) { +#else + if (0) { +#endif char *dsk; fd = open64(path, O_RDONLY); if (fd == -1) @@ -421,6 +425,14 @@ vn_open(char *path, int x1, int flags, int mode, vnode_t **vpp, int x2, int x3) return (errno); } +#ifdef __linux__ + if (!(flags & FCREAT) && S_ISBLK(st.st_mode)) { + flags |= O_DIRECT; + if (flags & FWRITE) + flags |= O_EXCL; + } +#endif + if (flags & FCREAT) old_umask = umask(0); diff --git a/zfs/lib/libzfs/include/libzfs.h b/zfs/lib/libzfs/include/libzfs.h index ca88e5a5a8..227e48d400 100644 --- a/zfs/lib/libzfs/include/libzfs.h +++ b/zfs/lib/libzfs/include/libzfs.h @@ -48,6 +48,20 @@ extern "C" { #define ZFS_MAXPROPLEN MAXPATHLEN #define ZPOOL_MAXPROPLEN MAXPATHLEN +/* + * Default device paths + */ + +#if defined(__sun__) || defined(__sun) +#define DISK_ROOT "/dev/dsk" +#define RDISK_ROOT "/dev/rdsk" +#define BACKUP_SLICE "s2" +#endif + +#ifdef __linux__ +#define DISK_ROOT "/dev" +#endif + /* * libzfs errors */ diff --git a/zfs/lib/libzfs/libzfs_import.c b/zfs/lib/libzfs/libzfs_import.c index bc6c33c0ff..9ea7198014 100644 --- a/zfs/lib/libzfs/libzfs_import.c +++ b/zfs/lib/libzfs/libzfs_import.c @@ -796,7 +796,7 @@ zpool_find_import_impl(libzfs_handle_t *hdl, int argc, char **argv, size_t pathleft; struct stat64 statbuf; nvlist_t *ret = NULL, *config; - static char *default_dir = "/dev/dsk"; + static char *default_dir = DISK_ROOT; int fd; pool_list_t pools = { 0 }; pool_entry_t *pe, *penext; diff --git a/zfs/lib/libzfs/libzfs_pool.c b/zfs/lib/libzfs/libzfs_pool.c index 048bb16cd7..f96f8ed632 100644 --- a/zfs/lib/libzfs/libzfs_pool.c +++ b/zfs/lib/libzfs/libzfs_pool.c @@ -1435,7 +1435,7 @@ zpool_find_vdev(zpool_handle_t *zhp, const char *path, boolean_t *avail_spare, if (guid != 0 && *end == '\0') { search = NULL; } else if (path[0] != '/') { - (void) snprintf(buf, sizeof (buf), "%s%s", "/dev/dsk/", path); + (void) snprintf(buf, sizeof (buf), "%s/%s", DISK_ROOT, path); search = buf; } else { search = path; @@ -2348,6 +2348,7 @@ zpool_vdev_name(libzfs_handle_t *hdl, zpool_handle_t *zhp, nvlist_t *nv) char buf[64]; vdev_stat_t *vs; uint_t vsc; + size_t droot_len = strlen(DISK_ROOT) + 1; if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NOT_PRESENT, &value) == 0) { @@ -2396,9 +2397,14 @@ zpool_vdev_name(libzfs_handle_t *hdl, zpool_handle_t *zhp, nvlist_t *nv) devid_str_free(newdevid); } - if (strncmp(path, "/dev/dsk/", 9) == 0) - path += 9; + if (strncmp(path, DISK_ROOT "/", droot_len) == 0) + path += droot_len; +#if defined(__sun__) || defined(__sun) + /* + * The following code strips the slice from the device path. + * This is only meaningful in Solaris. + */ if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_WHOLE_DISK, &value) == 0 && value) { char *tmp = zfs_strdup(hdl, path); @@ -2407,6 +2413,7 @@ zpool_vdev_name(libzfs_handle_t *hdl, zpool_handle_t *zhp, nvlist_t *nv) tmp[strlen(path) - 2] = '\0'; return (tmp); } +#endif } else { verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &path) == 0); @@ -2767,8 +2774,6 @@ zpool_obj_to_path(zpool_handle_t *zhp, uint64_t dsobj, uint64_t obj, free(mntpnt); } -#define RDISK_ROOT "/dev/rdsk" -#define BACKUP_SLICE "s2" /* * Don't start the slice at the default block of 34; many storage * devices will use a stripe width of 128k, so start there instead. diff --git a/zfs/zcmd/zpool/zpool_main.c b/zfs/zcmd/zpool/zpool_main.c index db0f8db397..7a51015a21 100644 --- a/zfs/zcmd/zpool/zpool_main.c +++ b/zfs/zcmd/zpool/zpool_main.c @@ -1469,7 +1469,7 @@ zpool_do_import(int argc, char **argv) if (searchdirs == NULL) { searchdirs = safe_malloc(sizeof (char *)); - searchdirs[0] = "/dev/dsk"; + searchdirs[0] = DISK_ROOT; nsearch = 1; } @@ -2223,14 +2223,15 @@ zpool_get_vdev_by_name(nvlist_t *nv, char *name) uint_t c, children; nvlist_t *match; char *path; + size_t droot_len = strlen(DISK_ROOT) + 1; if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN, &child, &children) != 0) { verify(nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &path) == 0); - if (strncmp(name, "/dev/dsk/", 9) == 0) - name += 9; - if (strncmp(path, "/dev/dsk/", 9) == 0) - path += 9; + if (strncmp(name, DISK_ROOT "/", droot_len) == 0) + name += droot_len; + if (strncmp(path, DISK_ROOT "/", droot_len) == 0) + path += droot_len; if (strcmp(name, path) == 0) return (nv); return (NULL); diff --git a/zfs/zcmd/zpool/zpool_vdev.c b/zfs/zcmd/zpool/zpool_vdev.c index 169ac2712d..6398d1610b 100644 --- a/zfs/zcmd/zpool/zpool_vdev.c +++ b/zfs/zcmd/zpool/zpool_vdev.c @@ -77,10 +77,6 @@ #include "zpool_util.h" -#define DISK_ROOT "/dev/dsk" -#define RDISK_ROOT "/dev/rdsk" -#define BACKUP_SLICE "s2" - /* * For any given vdev specification, we can have multiple errors. The * vdev_error() function keeps track of whether we have seen an error yet, and