aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRich Ercolani <[email protected]>2021-06-09 20:57:57 -0400
committerGitHub <[email protected]>2021-06-09 18:57:57 -0600
commit860051f1d1ef7ee995188b852d8da36bce85b1dc (patch)
treea351cbf5a0eae570e0afbe8e393cf93b30e09944
parent327c904615db9cfcd8c9e07cb56b8e36050a4048 (diff)
Added error for writing to /dev/ on Linux
Starting in Linux 5.10, trying to write to /dev/{null,zero} errors out. Prefer to inform people when this happens rather than hoping they guess what's wrong. Reviewed-by: Antonio Russo <[email protected]> Reviewed-by: Ahelenia ZiemiaƄska <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Reviewed-by: John Kennedy <[email protected]> Signed-off-by: Rich Ercolani <[email protected]> Closes: #11991
-rw-r--r--cmd/zfs/zfs_main.c38
-rw-r--r--lib/libzfs/libzfs_sendrecv.c1
2 files changed, 37 insertions, 2 deletions
diff --git a/cmd/zfs/zfs_main.c b/cmd/zfs/zfs_main.c
index c583053db..38bfdc91a 100644
--- a/cmd/zfs/zfs_main.c
+++ b/cmd/zfs/zfs_main.c
@@ -728,6 +728,32 @@ finish_progress(char *done)
pt_header = NULL;
}
+/* This function checks if the passed fd refers to /dev/null or /dev/zero */
+#ifdef __linux__
+static boolean_t
+is_dev_nullzero(int fd)
+{
+ struct stat st;
+ fstat(fd, &st);
+ return (major(st.st_rdev) == 1 && (minor(st.st_rdev) == 3 /* null */ ||
+ minor(st.st_rdev) == 5 /* zero */));
+}
+#endif
+
+static void
+note_dev_error(int err, int fd)
+{
+#ifdef __linux__
+ if (err == EINVAL && is_dev_nullzero(fd)) {
+ (void) fprintf(stderr,
+ gettext("Error: Writing directly to /dev/{null,zero} files"
+ " on certain kernels is not currently implemented.\n"
+ "(As a workaround, "
+ "try \"zfs send [...] | cat > /dev/null\")\n"));
+ }
+#endif
+}
+
static int
zfs_mount_and_share(libzfs_handle_t *hdl, const char *dataset, zfs_type_t type)
{
@@ -4572,11 +4598,16 @@ zfs_do_send(int argc, char **argv)
err = zfs_send_saved(zhp, &flags, STDOUT_FILENO,
resume_token);
+ if (err != 0)
+ note_dev_error(errno, STDOUT_FILENO);
zfs_close(zhp);
return (err != 0);
} else if (resume_token != NULL) {
- return (zfs_send_resume(g_zfs, &flags, STDOUT_FILENO,
- resume_token));
+ err = zfs_send_resume(g_zfs, &flags, STDOUT_FILENO,
+ resume_token);
+ if (err != 0)
+ note_dev_error(errno, STDOUT_FILENO);
+ return (err);
}
if (flags.skipmissing && !flags.replicate) {
@@ -4627,6 +4658,8 @@ zfs_do_send(int argc, char **argv)
err = zfs_send_one(zhp, fromname, STDOUT_FILENO, &flags,
redactbook);
zfs_close(zhp);
+ if (err != 0)
+ note_dev_error(errno, STDOUT_FILENO);
return (err != 0);
}
@@ -4703,6 +4736,7 @@ zfs_do_send(int argc, char **argv)
nvlist_free(dbgnv);
}
zfs_close(zhp);
+ note_dev_error(errno, STDOUT_FILENO);
return (err != 0);
}
diff --git a/lib/libzfs/libzfs_sendrecv.c b/lib/libzfs/libzfs_sendrecv.c
index 2ba673fd0..136255786 100644
--- a/lib/libzfs/libzfs_sendrecv.c
+++ b/lib/libzfs/libzfs_sendrecv.c
@@ -849,6 +849,7 @@ dump_ioctl(zfs_handle_t *zhp, const char *fromsnap, uint64_t fromsnap_obj,
case ERANGE:
case EFAULT:
case EROFS:
+ case EINVAL:
zfs_error_aux(hdl, "%s", strerror(errno));
return (zfs_error(hdl, EZFS_BADBACKUP, errbuf));