]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: improve fs referencing in tables
authorTim Hildering <hilderingt@posteo.net>
Mon, 4 Mar 2019 18:15:08 +0000 (19:15 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 8 Mar 2019 10:40:20 +0000 (11:40 +0100)
* Added member 'struct libmnt_table *tab' to libmnt_fs structure.
* Added 'mnt_fs_get_table()'.
* Removed overhead from 'mnt_table_{insert,move,remove}_fs().
* Added check to 'mnt_table_set_iter()' that entry is member of table.

[kzak@redhat.com: - add to libmount.sys
                  - add to docs
                  - cleanup commit message
                  - set fs->tab = NULL before mnt_unref_fs() in mnt_table_remove_fs()]

Signed-off-by: Tim Hildering <hilderingt@posteo.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/docs/libmount-sections.txt
libmount/src/fs.c
libmount/src/libmount.h.in
libmount/src/libmount.sym
libmount/src/mountP.h
libmount/src/tab.c

index 6767b00695659ccc757cd8387b97505f9d62e3c7..95debcfda66476944e2b7067663bf9d5d27266ff 100644 (file)
@@ -227,6 +227,7 @@ mnt_fs_get_source
 mnt_fs_get_srcpath
 mnt_fs_get_swaptype
 mnt_fs_get_tag
+mnt_fs_get_table
 mnt_fs_get_target
 mnt_fs_get_tid
 mnt_fs_get_usedsize
index 9971d6ae312a6190a9a8a872ef3b10ecb52943c4..147398955fa09522f20dc45ac4bbc02cabcd3404 100644 (file)
@@ -190,6 +190,7 @@ struct libmnt_fs *mnt_copy_fs(struct libmnt_fs *dest,
                        return NULL;
        }
 
+       dest->tab        = NULL;
        dest->id         = src->id;
        dest->parent     = src->parent;
        dest->devno      = src->devno;
@@ -445,6 +446,22 @@ int mnt_fs_streq_srcpath(struct libmnt_fs *fs, const char *path)
        return p && path && strcmp(p, path) == 0;
 }
 
+/**
+ * mnt_fs_get_table:
+ * @fs: table entry
+ * @tb: table that contains @fs
+ *
+ * Returns: 0 or negative number on error (if @fs or @tb is NULL).
+ */
+int mnt_fs_get_table(struct libmnt_fs *fs, struct libmnt_table **tb)
+{
+       if (!fs || !tb)
+               return -EINVAL;
+
+       *tb = fs->tab;
+       return 0;
+}
+
 /**
  * mnt_fs_streq_target:
  * @fs: fs
index fb86aaff9553a7b3da31bf734210d1139b7269eb..19535bd7ff94d85aee275b778f49b9482f6c3556 100644 (file)
@@ -439,6 +439,7 @@ extern int mnt_fs_set_userdata(struct libmnt_fs *fs, void *data);
 extern const char *mnt_fs_get_source(struct libmnt_fs *fs);
 extern int mnt_fs_set_source(struct libmnt_fs *fs, const char *source);
 extern const char *mnt_fs_get_srcpath(struct libmnt_fs *fs);
+extern int mnt_fs_get_table(struct libmnt_fs *fs, struct libmnt_table **tb);
 
 extern int mnt_fs_get_tag(struct libmnt_fs *fs, const char **name,
                          const char **value);
index 1d72cf4f7baacfc7afdac99f80b96aaa10c0ef1f..b92728ff68b83e6c76e82e1a8979a9192010060d 100644 (file)
@@ -344,6 +344,7 @@ MOUNT_2.33 {
 
 MOUNT_2.34 {
        mnt_context_next_remount;
+       mnt_fs_get_table;
        mnt_guess_system_root;
        mnt_table_find_fs;
        mnt_table_insert_fs;
index 7887c0a55dead592941aa18439b1a0a7e7354776..11fc2831554a682c08ed60e7206b3c71f1aad2cb 100644 (file)
@@ -170,6 +170,7 @@ struct libmnt_iter {
  */
 struct libmnt_fs {
        struct list_head ents;
+       struct libmnt_table *tab;
 
        int             refcount;       /* reference counter */
        int             id;             /* mountinfo[1]: ID */
index 674dc67e5b17796f293b3dadb7a97d7ba85f1788..6d2fdc0d5ad923ce6bdfa65908ce39c72a10e590 100644 (file)
@@ -443,11 +443,12 @@ int mnt_table_add_fs(struct libmnt_table *tb, struct libmnt_fs *fs)
        if (!tb || !fs)
                return -EINVAL;
 
-       if (!list_empty(&fs->ents))
+       if (fs->tab)
                return -EBUSY;
 
        mnt_ref_fs(fs);
        list_add_tail(&fs->ents, &tb->ents);
+       fs->tab = tb;
        tb->nents++;
 
        DBG(TAB, ul_debugobj(tb, "add entry: %s %s",
@@ -466,6 +467,7 @@ static int __table_insert_fs(
        else
                list_add_tail(&fs->ents, head);
 
+       fs->tab = tb;
        tb->nents++;
 
        DBG(TAB, ul_debugobj(tb, "insert entry: %s %s",
@@ -487,7 +489,6 @@ static int __table_insert_fs(
  * This function inncrements reference to @fs. Don't forget to use
  * mnt_unref_fs() after mnt_table_insert_fs() if you want to keep the @fs
  * referenced by the table only.
-
  *
  * Returns: 0 on success or negative number in case of error.
  */
@@ -497,10 +498,10 @@ int mnt_table_insert_fs(struct libmnt_table *tb, int before,
        if (!tb || !fs)
                return -EINVAL;
 
-       if (!list_empty(&fs->ents))
+       if (fs->tab)
                return -EBUSY;
 
-       if (pos && mnt_table_find_fs(tb, pos) < 1)
+       if (pos && pos->tab != tb)
                return -ENOENT;
 
        mnt_ref_fs(fs);
@@ -529,10 +530,7 @@ int mnt_table_move_fs(struct libmnt_table *src, struct libmnt_table *dst,
        if (!src || !dst || !fs)
                return -EINVAL;
 
-       if (mnt_table_find_fs(src, fs) < 1)
-               return -ENOENT;
-
-       if (pos && mnt_table_find_fs(dst, pos) < 1)
+       if (fs->tab != src || (pos && pos->tab != dst))
                return -ENOENT;
 
        /* remove from source */
@@ -557,9 +555,10 @@ int mnt_table_move_fs(struct libmnt_table *src, struct libmnt_table *dst,
  */
 int mnt_table_remove_fs(struct libmnt_table *tb, struct libmnt_fs *fs)
 {
-       if (!tb || !fs || mnt_table_find_fs(tb, fs) < 1)
+       if (!tb || !fs || fs->tab != tb)
                return -EINVAL;
 
+       fs->tab = NULL;
        list_del_init(&fs->ents);
 
        mnt_unref_fs(fs);
@@ -913,6 +912,9 @@ int mnt_table_set_iter(struct libmnt_table *tb, struct libmnt_iter *itr, struct
        if (!tb || !itr || !fs)
                return -EINVAL;
 
+       if (fs->tab != tb)
+               return -ENOENT;
+
        MNT_ITER_INIT(itr, &tb->ents);
        itr->p = &fs->ents;