mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-11-17 10:01:01 +03:00
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:
parent
bf80fb53f5
commit
64dfdaba37
@ -114,9 +114,11 @@ zpool_open_func(void *arg)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Ignore failed stats. We only want regular files and block devices.
|
* 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 ||
|
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;
|
return;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -132,14 +134,6 @@ zpool_open_func(void *arg)
|
|||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return;
|
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);
|
error = zpool_read_label(fd, &config, &num_labels);
|
||||||
if (error != 0) {
|
if (error != 0) {
|
||||||
(void) close(fd);
|
(void) close(fd);
|
||||||
|
@ -1243,10 +1243,21 @@ zpool_find_import_scan_dir(libpc_handle_t *hdl, pthread_mutex_t *lock,
|
|||||||
|
|
||||||
while ((dp = readdir64(dirp)) != NULL) {
|
while ((dp = readdir64(dirp)) != NULL) {
|
||||||
const char *name = dp->d_name;
|
const char *name = dp->d_name;
|
||||||
if (name[0] == '.' &&
|
if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
|
||||||
(name[1] == 0 || (name[1] == '.' && name[2] == 0)))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
switch (dp->d_type) {
|
||||||
|
case DT_UNKNOWN:
|
||||||
|
case DT_BLK:
|
||||||
|
#ifdef __FreeBSD__
|
||||||
|
case DT_CHR:
|
||||||
|
#endif
|
||||||
|
case DT_REG:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
zpool_find_import_scan_add_slice(hdl, lock, cache, path, name,
|
zpool_find_import_scan_add_slice(hdl, lock, cache, path, name,
|
||||||
order);
|
order);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user