]> git.proxmox.com Git - mirror_zfs.git/blobdiff - lib/libzfs_core/libzfs_core.c
OpenZFS 9102 - zfs should be able to initialize storage devices
[mirror_zfs.git] / lib / libzfs_core / libzfs_core.c
index 1baec04a4077f7231b2fff15124996fb75f3209a..524a637e4a38e8eafed2dff8f855d95cea0841d0 100644 (file)
@@ -1397,3 +1397,40 @@ lzc_reopen(const char *pool_name, boolean_t scrub_restart)
        nvlist_free(args);
        return (error);
 }
+
+/*
+ * Changes initializing state.
+ *
+ * vdevs should be a list of (<key>, guid) where guid is a uint64 vdev GUID.
+ * The key is ignored.
+ *
+ * If there are errors related to vdev arguments, per-vdev errors are returned
+ * in an nvlist with the key "vdevs". Each error is a (guid, errno) pair where
+ * guid is stringified with PRIu64, and errno is one of the following as
+ * an int64_t:
+ *     - ENODEV if the device was not found
+ *     - EINVAL if the devices is not a leaf or is not concrete (e.g. missing)
+ *     - EROFS if the device is not writeable
+ *     - EBUSY start requested but the device is already being initialized
+ *     - ESRCH cancel/suspend requested but device is not being initialized
+ *
+ * If the errlist is empty, then return value will be:
+ *     - EINVAL if one or more arguments was invalid
+ *     - Other spa_open failures
+ *     - 0 if the operation succeeded
+ */
+int
+lzc_initialize(const char *poolname, pool_initialize_func_t cmd_type,
+    nvlist_t *vdevs, nvlist_t **errlist)
+{
+       int error;
+       nvlist_t *args = fnvlist_alloc();
+       fnvlist_add_uint64(args, ZPOOL_INITIALIZE_COMMAND, (uint64_t)cmd_type);
+       fnvlist_add_nvlist(args, ZPOOL_INITIALIZE_VDEVS, vdevs);
+
+       error = lzc_ioctl(ZFS_IOC_POOL_INITIALIZE, poolname, args, errlist);
+
+       fnvlist_free(args);
+
+       return (error);
+}