]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: save task ID for mountinfo tiles
authorKarel Zak <kzak@redhat.com>
Thu, 28 Jun 2012 13:40:16 +0000 (15:40 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 28 Jun 2012 13:40:16 +0000 (15:40 +0200)
Add new function mnt_fs_get_tid() to get task ID for the given filesystem.

Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/fs.c
libmount/src/libmount.h.in
libmount/src/libmount.sym
libmount/src/mountP.h
libmount/src/tab_parse.c

index 543ffb153728e8473eed4f872b8df94df38aeaab..ff930806fc20236b1f13654e76381d759b3204c2 100644 (file)
@@ -139,6 +139,7 @@ struct libmnt_fs *mnt_copy_fs(struct libmnt_fs *dest,
        dest->id         = src->id;
        dest->parent     = src->parent;
        dest->devno      = src->devno;
+       dest->tid        = src->tid;
 
        if (cpy_str_at_offset(dest, src, offsetof(struct libmnt_fs, source)))
                goto err;
@@ -1157,6 +1158,18 @@ dev_t mnt_fs_get_devno(struct libmnt_fs *fs)
        return fs ? fs->devno : 0;
 }
 
+/**
+ * mnt_fs_get_tid:
+ * @fs: /proc/<tid>/mountinfo entry
+ *
+ * Returns: TID (task ID) for filesystems read from mountinfo file
+ */
+pid_t mnt_fs_get_tid(struct libmnt_fs *fs)
+{
+       assert(fs);
+       return fs ? fs->tid : 0;
+}
+
 /**
  * mnt_fs_get_option:
  * @fs: fstab/mtab/mountinfo entry pointer
@@ -1406,7 +1419,10 @@ int mnt_fs_print_debug(struct libmnt_fs *fs, FILE *file)
                fprintf(file, "parent: %d\n", mnt_fs_get_parent_id(fs));
        if (mnt_fs_get_devno(fs))
                fprintf(file, "devno:  %d:%d\n", major(mnt_fs_get_devno(fs)),
-                                                minor(mnt_fs_get_devno(fs)));
+                                               minor(mnt_fs_get_devno(fs)));
+       if (mnt_fs_get_tid(fs))
+               fprintf(file, "tid:    %d\n", mnt_fs_get_tid(fs));
+
        return 0;
 }
 
index e12243962056840ae8512369d2b7c550649e194e..6b87f984c310ae6b3391690455d643bb54cd8ca9 100644 (file)
@@ -274,6 +274,7 @@ extern int mnt_fs_set_bindsrc(struct libmnt_fs *fs, const char *src);
 extern int mnt_fs_get_id(struct libmnt_fs *fs);
 extern int mnt_fs_get_parent_id(struct libmnt_fs *fs);
 extern dev_t mnt_fs_get_devno(struct libmnt_fs *fs);
+extern pid_t mnt_fs_get_tid(struct libmnt_fs *fs);
 
 extern const char *mnt_fs_get_swaptype(struct libmnt_fs *fs);
 extern off_t mnt_fs_get_size(struct libmnt_fs *fs);
index d4d5b84bf4de58d78654b72053c4c0208ab4fff9..d07b570f1403a02314a097bf99476eb71783f145 100644 (file)
@@ -239,8 +239,9 @@ global:
        mnt_table_parse_swaps;
        mnt_get_mountpoint;
        mnt_get_swaps_path;
-       mnt_fs_get_swaptype;
+       mnt_fs_get_priority;
        mnt_fs_get_size;
+       mnt_fs_get_swaptype;
+       mnt_fs_get_tid;
        mnt_fs_get_usedsize;
-       mnt_fs_get_priority;
 } MOUNT_2.21;
index f7cd7d53ddd085ab6873fd1143cfe0cb76b39b36..a2922c2b3edce97b1d348dd2b51432c720f25794 100644 (file)
@@ -218,6 +218,7 @@ struct libmnt_fs {
        int             priority;       /* swaps[5]: swap priority */
 
        int             flags;          /* MNT_FS_* flags */
+       pid_t           tid;            /* /proc/<tid>/mountinfo otherwise zero */
 
        void            *userdata;      /* library independent data */
 };
index 73a7f83c8b54aadb3e25e486e625d8a1acd79ac1..ab5d51acd4dff0bdb28d7cb2002c45dab768531d 100644 (file)
@@ -423,6 +423,35 @@ err:
        return tb->errcb ? tb->errcb(tb, filename, *nlines) : 1;
 }
 
+static pid_t path_to_tid(const char *filename)
+{
+       char *path = mnt_resolve_path(filename, NULL);
+       char *p, *end = NULL;
+       pid_t tid = 0;
+
+       if (!path)
+               goto done;
+       p = strrchr(path, '/');
+       if (!p)
+               goto done;
+       *p = '\0';
+       p = strrchr(path, '/');
+       if (!p)
+               goto done;
+       p++;
+
+       errno = 0;
+       tid = strtol(p, &end, 10);
+       if (errno || p == end || (end && *end)) {
+               tid = 0;
+               goto done;
+       }
+       DBG(TAB, mnt_debug("TID for %s is %d", filename, tid));
+done:
+       free(path);
+       return tid;
+}
+
 /**
  * mnt_table_parse_stream:
  * @tb: tab pointer
@@ -436,6 +465,7 @@ int mnt_table_parse_stream(struct libmnt_table *tb, FILE *f, const char *filenam
        int nlines = 0;
        int rc = -1;
        int flags = 0;
+       pid_t tid = -1;
 
        assert(tb);
        assert(f);
@@ -460,6 +490,11 @@ int mnt_table_parse_stream(struct libmnt_table *tb, FILE *f, const char *filenam
                if (!rc) {
                        rc = mnt_table_add_fs(tb, fs);
                        fs->flags |= flags;
+                       if (tb->fmt == MNT_FMT_MOUNTINFO && filename) {
+                               if (tid == -1)
+                                       tid = path_to_tid(filename);
+                               fs->tid = tid;
+                       }
                }
                if (rc) {
                        mnt_free_fs(fs);