handle sub volumes of the btrFS

OBS-URL: https://build.opensuse.org/package/show/Base:System/psmisc?expand=0&rev=114
This commit is contained in:
Dr. Werner Fink 2018-11-15 06:48:52 +00:00 committed by Git OBS Bridge
parent dee14919e6
commit f13b879ded
2 changed files with 81 additions and 50 deletions

View File

@ -1,4 +1,4 @@
From b746c58eb31e00d1a5545e3d90bea0b768265ad7 Mon Sep 17 00:00:00 2001 From 2588a03273329961e5eefe6fed695b8f80a352e3 Mon Sep 17 00:00:00 2001
From: Werner Fink <werner@suse.de> From: Werner Fink <werner@suse.de>
Date: Mon, 22 Oct 2018 12:02:50 +0200 Date: Mon, 22 Oct 2018 12:02:50 +0200
Subject: [PATCH] Use mountinfo to be able to use the mount identity Subject: [PATCH] Use mountinfo to be able to use the mount identity
@ -16,11 +16,11 @@ Support also BtrFS with its various subvolumes
Signed-off-by: Werner Fink <werner@suse.de> Signed-off-by: Werner Fink <werner@suse.de>
--- ---
configure.ac | 18 +- configure.ac | 18 +-
src/fuser.c | 627 ++++++++++++++++++++++++++++--------- src/fuser.c | 644 ++++++++++++++++++++++++++++---------
src/fuser.h | 27 +- src/fuser.h | 27 +-
testsuite/Makefile.am | 3 +- testsuite/Makefile.am | 3 +-
testsuite/killall.test/killall.exp | 4 + testsuite/killall.test/killall.exp | 4 +
5 files changed, 526 insertions(+), 153 deletions(-) 5 files changed, 543 insertions(+), 153 deletions(-)
diff --git configure.ac configure.ac diff --git configure.ac configure.ac
index 176a2fc..d8d3366 100644 index 176a2fc..d8d3366 100644
@ -66,7 +66,7 @@ index 176a2fc..d8d3366 100644
dnl Checks for typedefs, structures, and compiler characteristics. dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST AC_C_CONST
diff --git src/fuser.c src/fuser.c diff --git src/fuser.c src/fuser.c
index c44cee8..970b52d 100644 index c44cee8..7ee9b49 100644
--- src/fuser.c --- src/fuser.c
+++ src/fuser.c +++ src/fuser.c
@@ -32,6 +32,10 @@ @@ -32,6 +32,10 @@
@ -250,7 +250,7 @@ index c44cee8..970b52d 100644
+ dev_tmp->mnt_id = this_name->mnt_id; + dev_tmp->mnt_id = this_name->mnt_id;
+ if (dev_tmp->device != subvol) + if (dev_tmp->device != subvol)
+ add_subvol(&dev_tmp->vol, subvol, this_name->mnt_id); + add_subvol(&dev_tmp->vol, subvol, this_name->mnt_id);
+ dev_tmp->mnt_id = this_name->mnt_id; + else dev_tmp->vol = NULL;
dev_tmp->next = dev_head; dev_tmp->next = dev_head;
*dev_list = dev_tmp; *dev_list = dev_tmp;
} }
@ -367,7 +367,38 @@ index c44cee8..970b52d 100644
} }
return 1; return 1;
} }
@@ -1162,16 +1258,11 @@ int main(int argc, char *argv[]) @@ -953,6 +1049,21 @@ free_inodes(struct inode_list **match_inodes)
/*
* Free up structures allocated in add_device
*/
+
+static void
+free_subvol(struct subvol **volumes)
+{
+ struct subvol *vol_tmp, *vol_next;
+
+ vol_tmp = *volumes;
+ while (vol_tmp != NULL) {
+ vol_next = vol_tmp->next;
+ free(vol_tmp);
+ vol_tmp = vol_next;
+ }
+ *volumes =NULL;
+}
+
static void
free_devices(struct device_list **match_devices)
{
@@ -960,6 +1071,8 @@ free_devices(struct device_list **match_devices)
device_tmp = *match_devices;
while(device_tmp != NULL) {
+ if (device_tmp->vol)
+ free_subvol(&device_tmp->vol);
device_next = device_tmp->next;
free(device_tmp);
device_tmp = device_next;
@@ -1162,16 +1275,11 @@ int main(int argc, char *argv[])
skip_argv = 1; skip_argv = 1;
//while(option != '\0') option++; //while(option != '\0') option++;
if (strcmp(argv[argc_cnt], "tcp") == 0) if (strcmp(argv[argc_cnt], "tcp") == 0)
@ -389,7 +420,7 @@ index c44cee8..970b52d 100644
else else
usage(_ usage(_
("Invalid namespace name")); ("Invalid namespace name"));
@@ -1211,7 +1302,7 @@ int main(int argc, char *argv[]) @@ -1211,7 +1319,7 @@ int main(int argc, char *argv[])
} }
#if defined(WITH_MOUNTINFO_LIST) #if defined(WITH_MOUNTINFO_LIST)
@ -398,7 +429,7 @@ index c44cee8..970b52d 100644
thestat = mntstat; thestat = mntstat;
#endif #endif
/* an option */ /* an option */
@@ -1525,7 +1616,7 @@ print_matches(struct names *names_head, const opt_type opts, @@ -1525,7 +1633,7 @@ print_matches(struct names *names_head, const opt_type opts,
} }
@ -407,7 +438,7 @@ index c44cee8..970b52d 100644
{ {
char pathname[256]; char pathname[256];
struct stat *st; struct stat *st;
@@ -1537,6 +1628,15 @@ static struct stat *get_pidstat(const pid_t pid, const char *filename) @@ -1537,6 +1645,15 @@ static struct stat *get_pidstat(const pid_t pid, const char *filename)
free(st); free(st);
return NULL; return NULL;
} }
@ -423,7 +454,7 @@ index c44cee8..970b52d 100644
return st; return st;
} }
@@ -1551,7 +1651,8 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, @@ -1551,7 +1668,8 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head,
struct inode_list *ino_tmp; struct inode_list *ino_tmp;
struct device_list *dev_tmp; struct device_list *dev_tmp;
struct unixsocket_list *sock_tmp; struct unixsocket_list *sock_tmp;
@ -433,7 +464,7 @@ index c44cee8..970b52d 100644
char *dirpath; char *dirpath;
char filepath[PATH_MAX]; char filepath[PATH_MAX];
@@ -1590,11 +1691,27 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, @@ -1590,11 +1708,27 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head,
} }
for (dev_tmp = dev_head; dev_tmp != NULL; for (dev_tmp = dev_head; dev_tmp != NULL;
dev_tmp = dev_tmp->next) { dev_tmp = dev_tmp->next) {
@ -464,7 +495,7 @@ index c44cee8..970b52d 100644
add_matched_proc(dev_tmp->name, add_matched_proc(dev_tmp->name,
pid, uid, pid, uid,
ACCESS_FILEWR | ACCESS_FILEWR |
@@ -1616,9 +1733,10 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, @@ -1616,9 +1750,10 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head,
continue; continue;
} }
if (st.st_ino == ino_tmp->inode) { if (st.st_ino == ino_tmp->inode) {
@ -477,7 +508,7 @@ index c44cee8..970b52d 100644
add_matched_proc(ino_tmp->name, add_matched_proc(ino_tmp->name,
pid, uid, pid, uid,
ACCESS_FILEWR | ACCESS_FILEWR |
@@ -1647,31 +1765,54 @@ check_map(const pid_t pid, const char *filename, @@ -1647,31 +1782,54 @@ check_map(const pid_t pid, const char *filename,
FILE *fp; FILE *fp;
unsigned long long tmp_inode; unsigned long long tmp_inode;
unsigned int tmp_maj, tmp_min; unsigned int tmp_maj, tmp_min;
@ -542,7 +573,7 @@ index c44cee8..970b52d 100644
} }
fclose(fp); fclose(fp);
} }
@@ -1695,6 +1836,7 @@ static uid_t getpiduid(const pid_t pid) @@ -1695,6 +1853,7 @@ static uid_t getpiduid(const pid_t pid)
* fill_unix_cache : Create a list of Unix sockets * fill_unix_cache : Create a list of Unix sockets
* This list is used later for matching purposes * This list is used later for matching purposes
*/ */
@ -550,7 +581,7 @@ index c44cee8..970b52d 100644
void fill_unix_cache(struct unixsocket_list **unixsocket_head) void fill_unix_cache(struct unixsocket_list **unixsocket_head)
{ {
FILE *fp; FILE *fp;
@@ -1711,6 +1853,8 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head) @@ -1711,6 +1870,8 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head)
while (fgets(line, BUFSIZ, fp) != NULL) { while (fgets(line, BUFSIZ, fp) != NULL) {
char *path; char *path;
char *scanned_path = NULL; char *scanned_path = NULL;
@ -559,7 +590,7 @@ index c44cee8..970b52d 100644
if (sscanf(line, "%*x: %*x %*x %*x %*x %*d %d %ms", if (sscanf(line, "%*x: %*x %*x %*x %*x %*d %d %ms",
&scanned_inode, &scanned_path) != 2) { &scanned_inode, &scanned_path) != 2) {
if (scanned_path) if (scanned_path)
@@ -1726,6 +1870,8 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head) @@ -1726,6 +1887,8 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head)
free(path); free(path);
continue; continue;
} }
@ -568,7 +599,7 @@ index c44cee8..970b52d 100644
if ((newsocket = (struct unixsocket_list *) if ((newsocket = (struct unixsocket_list *)
malloc(sizeof(struct unixsocket_list))) == NULL) { malloc(sizeof(struct unixsocket_list))) == NULL) {
free(path); free(path);
@@ -1734,6 +1880,7 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head) @@ -1734,6 +1897,7 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head)
newsocket->sun_name = strdup(scanned_path); newsocket->sun_name = strdup(scanned_path);
newsocket->inode = st.st_ino; newsocket->inode = st.st_ino;
newsocket->dev = st.st_dev; newsocket->dev = st.st_dev;
@ -576,7 +607,7 @@ index c44cee8..970b52d 100644
newsocket->net_inode = scanned_inode; newsocket->net_inode = scanned_inode;
newsocket->next = *unixsocket_head; newsocket->next = *unixsocket_head;
*unixsocket_head = newsocket; *unixsocket_head = newsocket;
@@ -1746,6 +1893,7 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head) @@ -1746,6 +1910,7 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head)
/* /*
* Free up the list of Unix sockets * Free up the list of Unix sockets
*/ */
@ -584,7 +615,7 @@ index c44cee8..970b52d 100644
void clear_unix_cache(struct unixsocket_list **unixsocket_head) void clear_unix_cache(struct unixsocket_list **unixsocket_head)
{ {
while(*unixsocket_head != NULL) { while(*unixsocket_head != NULL) {
@@ -1913,30 +2061,22 @@ scan_mounts(struct names *names_head, struct inode_list *ino_head, @@ -1913,30 +2078,22 @@ scan_mounts(struct names *names_head, struct inode_list *ino_head,
{ {
struct device_list *dev_tmp; struct device_list *dev_tmp;
struct inode_list *ino_tmp; struct inode_list *ino_tmp;
@ -625,7 +656,7 @@ index c44cee8..970b52d 100644
add_special_proc(dev_tmp->name, PTYPE_MOUNT, 0, add_special_proc(dev_tmp->name, PTYPE_MOUNT, 0,
find_mountp); find_mountp);
} }
@@ -1948,7 +2088,6 @@ scan_mounts(struct names *names_head, struct inode_list *ino_head, @@ -1948,7 +2105,6 @@ scan_mounts(struct names *names_head, struct inode_list *ino_head,
find_mountp); find_mountp);
} }
} }
@ -633,7 +664,7 @@ index c44cee8..970b52d 100644
} }
static void static void
@@ -1998,16 +2137,44 @@ scan_swaps(struct names *names_head, struct inode_list *ino_head, @@ -1998,16 +2154,44 @@ scan_swaps(struct names *names_head, struct inode_list *ino_head,
fclose(fp); fclose(fp);
} }
@ -682,7 +713,7 @@ index c44cee8..970b52d 100644
{ {
list_t *ptr, *tmp; list_t *ptr, *tmp;
@@ -2018,72 +2185,244 @@ static void clear_mntinfo(void) @@ -2018,72 +2202,244 @@ static void clear_mntinfo(void)
} }
} }
@ -824,7 +855,12 @@ index c44cee8..970b52d 100644
+ } + }
+ return ret == 2 ? 0 : -1; + return ret == 2 ? 0 : -1;
+} +}
+
- /* Sort mount points accordingly to the reverse mount order */
- initial(&sort);
- for (mid = 1; mid <= max; mid++) {
- list_t *ptr, *tmp;
- list_for_each_safe(ptr, tmp, &mntinfo) {
+#if defined(HAS_NAME_TO_HANDLE_AT) +#if defined(HAS_NAME_TO_HANDLE_AT)
+static int +static int
+get_mountid(const char *path) +get_mountid(const char *path)
@ -853,12 +889,7 @@ index c44cee8..970b52d 100644
+ int ret = -1; + int ret = -1;
+ +
+ *mountinfo = NULL; + *mountinfo = NULL;
+
- /* Sort mount points accordingly to the reverse mount order */
- initial(&sort);
- for (mid = 1; mid <= max; mid++) {
- list_t *ptr, *tmp;
- list_for_each_safe(ptr, tmp, &mntinfo) {
+#if defined(HAS_NAME_TO_HANDLE_AT) +#if defined(HAS_NAME_TO_HANDLE_AT)
+ if (mnt_id >= 0) { + if (mnt_id >= 0) {
+ list_t *ptr; + list_t *ptr;
@ -940,11 +971,11 @@ index c44cee8..970b52d 100644
- if (mid != mnt->parid) - if (mid != mnt->parid)
+ +
+ if (nlen != mnt->nlen) + if (nlen != mnt->nlen)
continue; + continue;
- move_head(ptr, &sort);
+ +
+ if (strcmp(use, mnt->mpoint)) + if (strcmp(use, mnt->mpoint))
+ continue; continue;
- move_head(ptr, &sort);
+ +
+ ret = 0; + ret = 0;
+ errno = 0; + errno = 0;
@ -971,7 +1002,7 @@ index c44cee8..970b52d 100644
/* /*
* Determine device of links below /proc/ * Determine device of links below /proc/
*/ */
@@ -2091,8 +2430,7 @@ static int mntstat(const char *path, struct stat *buf) @@ -2091,8 +2447,7 @@ static int mntstat(const char *path, struct stat *buf)
{ {
char name[PATH_MAX + 1]; char name[PATH_MAX + 1];
const char *use; const char *use;
@ -981,7 +1012,7 @@ index c44cee8..970b52d 100644
if ((use = realpath(path, name)) == NULL || *use != '/') if ((use = realpath(path, name)) == NULL || *use != '/')
{ {
@@ -2104,27 +2442,26 @@ static int mntstat(const char *path, struct stat *buf) @@ -2104,27 +2459,26 @@ static int mntstat(const char *path, struct stat *buf)
errno = 0; errno = 0;
return stat(path, buf); return stat(path, buf);
} }

View File

@ -1,6 +1,6 @@
From 9c6fbdcb126ed8d0567ac3b88dac1bf34d4036fb Mon Sep 17 00:00:00 2001 From d4b2099ffd77d1fdea380ac42326b11a5be35e72 Mon Sep 17 00:00:00 2001
From: Werner Fink <werner@suse.de> From: Werner Fink <werner@suse.de>
Date: Wed, 14 Nov 2018 08:49:45 +0100 Date: Thu, 15 Nov 2018 07:41:23 +0100
Subject: [PATCH] Use new statx(2) system call to avoid hangs on NFS Subject: [PATCH] Use new statx(2) system call to avoid hangs on NFS
Signed-off-by: Werner Fink <werner@suse.de> Signed-off-by: Werner Fink <werner@suse.de>
@ -90,7 +90,7 @@ index d8d3366..81d3674 100644
# Enable hardened compile and link flags # Enable hardened compile and link flags
AC_ARG_ENABLE([harden_flags], AC_ARG_ENABLE([harden_flags],
diff --git src/fuser.c src/fuser.c diff --git src/fuser.c src/fuser.c
index 970b52d..e2d14bf 100644 index 7ee9b49..3f512de 100644
--- src/fuser.c --- src/fuser.c
+++ src/fuser.c +++ src/fuser.c
@@ -63,7 +63,7 @@ @@ -63,7 +63,7 @@
@ -122,7 +122,7 @@ index 970b52d..e2d14bf 100644
find_mountpoint(this_name->filename, &mountinfo) != 0) { find_mountpoint(this_name->filename, &mountinfo) != 0) {
if (errno == ENOENT) if (errno == ENOENT)
fprintf(stderr, fprintf(stderr,
@@ -1233,9 +1229,7 @@ int main(int argc, char *argv[]) @@ -1250,9 +1246,7 @@ int main(int argc, char *argv[])
opts |= OPT_INTERACTIVE; opts |= OPT_INTERACTIVE;
break; break;
case 'I': case 'I':
@ -132,7 +132,7 @@ index 970b52d..e2d14bf 100644
break; break;
case 'k': case 'k':
opts |= OPT_KILL; opts |= OPT_KILL;
@@ -1301,10 +1295,11 @@ int main(int argc, char *argv[]) @@ -1318,10 +1312,11 @@ int main(int argc, char *argv[])
continue; continue;
} }
@ -147,7 +147,7 @@ index 970b52d..e2d14bf 100644
/* an option */ /* an option */
/* Not an option, must be a file specification */ /* Not an option, must be a file specification */
if ((this_name = malloc(sizeof(struct names))) == NULL) if ((this_name = malloc(sizeof(struct names))) == NULL)
@@ -1624,7 +1619,7 @@ static struct stat *get_pidstat(const pid_t pid, const char *filename, int *id) @@ -1641,7 +1636,7 @@ static struct stat *get_pidstat(const pid_t pid, const char *filename, int *id)
if ((st = (struct stat *)malloc(sizeof(struct stat))) == NULL) if ((st = (struct stat *)malloc(sizeof(struct stat))) == NULL)
return NULL; return NULL;
snprintf(pathname, 256, "/proc/%d/%s", pid, filename); snprintf(pathname, 256, "/proc/%d/%s", pid, filename);
@ -156,7 +156,7 @@ index 970b52d..e2d14bf 100644
free(st); free(st);
return NULL; return NULL;
} }
@@ -1671,7 +1666,7 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, @@ -1688,7 +1683,7 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head,
snprintf(filepath, sizeof filepath - 1, "/proc/%d/%s/%s", snprintf(filepath, sizeof filepath - 1, "/proc/%d/%s/%s",
pid, dirname, direntry->d_name); pid, dirname, direntry->d_name);
@ -165,7 +165,7 @@ index 970b52d..e2d14bf 100644
if (errno != ENOENT && errno != ENOTDIR) { if (errno != ENOENT && errno != ENOTDIR) {
fprintf(stderr, _("Cannot stat file %s: %s\n"), fprintf(stderr, _("Cannot stat file %s: %s\n"),
filepath, strerror(errno)); filepath, strerror(errno));
@@ -1726,7 +1721,7 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head, @@ -1743,7 +1738,7 @@ check_dir(const pid_t pid, const char *dirname, struct device_list *dev_head,
if (thedev != ino_tmp->device) if (thedev != ino_tmp->device)
continue; continue;
if (!st.st_ino if (!st.st_ino
@ -174,7 +174,7 @@ index 970b52d..e2d14bf 100644
fprintf(stderr, fprintf(stderr,
_("Cannot stat file %s: %s\n"), _("Cannot stat file %s: %s\n"),
filepath, strerror(errno)); filepath, strerror(errno));
@@ -1824,11 +1819,11 @@ static uid_t getpiduid(const pid_t pid) @@ -1841,11 +1836,11 @@ static uid_t getpiduid(const pid_t pid)
if (asprintf(&pathname, "/proc/%d", pid) < 0) if (asprintf(&pathname, "/proc/%d", pid) < 0)
return 0; return 0;
@ -190,7 +190,7 @@ index 970b52d..e2d14bf 100644
return st.st_uid; return st.st_uid;
} }
@@ -1866,7 +1861,7 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head) @@ -1883,7 +1878,7 @@ void fill_unix_cache(struct unixsocket_list **unixsocket_head)
path = scanned_path; path = scanned_path;
if (*scanned_path == '@') if (*scanned_path == '@')
scanned_path++; scanned_path++;
@ -199,7 +199,7 @@ index 970b52d..e2d14bf 100644
free(path); free(path);
continue; continue;
} }
@@ -2001,7 +1996,7 @@ static dev_t find_net_dev(void) @@ -2018,7 +2013,7 @@ static dev_t find_net_dev(void)
fprintf(stderr, _("Cannot open a network socket.\n")); fprintf(stderr, _("Cannot open a network socket.\n"));
return -1; return -1;
} }
@ -208,7 +208,7 @@ index 970b52d..e2d14bf 100644
fprintf(stderr, _("Cannot find socket's device number.\n")); fprintf(stderr, _("Cannot find socket's device number.\n"));
close(skt); close(skt);
return -1; return -1;
@@ -2034,7 +2029,7 @@ scan_knfsd(struct names *names_head, struct inode_list *ino_head, @@ -2051,7 +2046,7 @@ scan_knfsd(struct names *names_head, struct inode_list *ino_head,
if ((find_space = strpbrk(line, " \t")) == NULL) if ((find_space = strpbrk(line, " \t")) == NULL)
continue; continue;
*find_space = '\0'; *find_space = '\0';
@ -217,7 +217,7 @@ index 970b52d..e2d14bf 100644
continue; continue;
} }
/* Scan the devices */ /* Scan the devices */
@@ -2069,7 +2064,7 @@ scan_mounts(struct names *names_head, struct inode_list *ino_head, @@ -2086,7 +2081,7 @@ scan_mounts(struct names *names_head, struct inode_list *ino_head,
mntinfo_t *mnt = list_entry(ptr, mntinfo_t); mntinfo_t *mnt = list_entry(ptr, mntinfo_t);
const char *find_mountp = mnt->mpoint; const char *find_mountp = mnt->mpoint;
@ -226,7 +226,7 @@ index 970b52d..e2d14bf 100644
continue; continue;
/* Scan the devices */ /* Scan the devices */
@@ -2116,7 +2111,7 @@ scan_swaps(struct names *names_head, struct inode_list *ino_head, @@ -2133,7 +2128,7 @@ scan_swaps(struct names *names_head, struct inode_list *ino_head,
if (*find_space == '\0') if (*find_space == '\0')
continue; continue;
} }
@ -235,7 +235,7 @@ index 970b52d..e2d14bf 100644
continue; continue;
} }
/* Scan the devices */ /* Scan the devices */
@@ -2279,7 +2274,7 @@ out: @@ -2296,7 +2291,7 @@ out:
struct stat lst; struct stat lst;
snprintf(pathname, 256, "/proc/%d/fd/%s", pid, fd); snprintf(pathname, 256, "/proc/%d/fd/%s", pid, fd);
@ -244,7 +244,7 @@ index 970b52d..e2d14bf 100644
if (lst.st_mode & S_IWUSR) if (lst.st_mode & S_IWUSR)
info->flags |= O_WRONLY; info->flags |= O_WRONLY;
ret++; ret++;
@@ -2422,49 +2417,6 @@ out: @@ -2439,49 +2434,6 @@ out:
return ret; return ret;
} }