libzutil: import: filter out unsuitable files earlier

Only accept the right type of file, if available, and reject too-small
files before opening them on Linux

Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Ryan Moeller <ryan@iXsystems.com>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #12105
This commit is contained in:
наб
2021-05-22 16:29:53 +02:00
committed by Brian Behlendorf
parent bf80fb53f5
commit 64dfdaba37
2 changed files with 16 additions and 11 deletions
+3 -9
View File
@@ -114,9 +114,11 @@ zpool_open_func(void *arg)
/*
* Ignore failed stats. We only want regular files and block devices.
* Ignore files that are too small to hold a zpool.
*/
if (stat64(rn->rn_name, &statbuf) != 0 ||
(!S_ISREG(statbuf.st_mode) && !S_ISBLK(statbuf.st_mode)))
(!S_ISREG(statbuf.st_mode) && !S_ISBLK(statbuf.st_mode)) ||
(S_ISREG(statbuf.st_mode) && statbuf.st_size < SPA_MINDEVSIZE))
return;
/*
@@ -132,14 +134,6 @@ zpool_open_func(void *arg)
if (fd < 0)
return;
/*
* This file is too small to hold a zpool
*/
if (S_ISREG(statbuf.st_mode) && statbuf.st_size < SPA_MINDEVSIZE) {
(void) close(fd);
return;
}
error = zpool_read_label(fd, &config, &num_labels);
if (error != 0) {
(void) close(fd);