]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lsfd: (refactor) make the code comparing struct lock objects reusable
authorMasatake YAMATO <yamato@redhat.com>
Wed, 15 Nov 2023 19:03:23 +0000 (04:03 +0900)
committerMasatake YAMATO <yamato@redhat.com>
Thu, 23 Nov 2023 13:09:41 +0000 (22:09 +0900)
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
misc-utils/lslocks.c

index 2d4e7c6b85ba24f1f894990cbb126c49a41435cc..d492cc14537a2fd66cbfeff7482932e37a1ee238 100644 (file)
@@ -293,6 +293,18 @@ struct override_info {
        const char *cmdname;
 };
 
+static bool is_co_holder(struct lock *l, struct lock *m)
+{
+       return (l->start == m->start &&
+               l->end == m->end &&
+               l->inode == m->inode &&
+               l->dev == m->dev &&
+               l->mandatory == m->mandatory &&
+               l->blocked == m->blocked &&
+               strcmp(l->type, m->type) == 0 &&
+               strcmp(l->mode, m->mode) == 0);
+}
+
 static void patch_lock(struct lock *l, void *fallback)
 {
        struct lock_tnode tmp = { .dev = l->dev, .inode = l->inode, };
@@ -304,14 +316,7 @@ static void patch_lock(struct lock *l, void *fallback)
 
        list_for_each(p, &(*head)->chain) {
                struct lock *m = list_entry(p, struct lock, locks);
-               if (l->start == m->start &&
-                   l->end == m->end &&
-                   l->inode == m->inode &&
-                   l->dev == m->dev &&
-                   l->mandatory == m->mandatory &&
-                   l->blocked == m->blocked &&
-                   strcmp(l->type, m->type) == 0 &&
-                   strcmp(l->mode, m->mode) == 0) {
+               if (is_co_holder(l, m)) {
                        /* size and id can be ignored. */
                        l->pid = m->pid;
                        l->cmdname = xstrdup(m->cmdname);