diff options
author | Karel Zak | 2013-08-21 12:31:43 +0200 |
---|---|---|
committer | Karel Zak | 2013-08-21 12:48:42 +0200 |
commit | 26d0c0aefde9a94f29d9850514fcbcf638eb8728 (patch) | |
tree | cfe01b73d0d399baeeb5bdf1ffb8e6cdd6a38708 /libmount/src/context.c | |
parent | pylibmount: remove Context_get_table() (diff) | |
download | kernel-qcow2-util-linux-26d0c0aefde9a94f29d9850514fcbcf638eb8728.tar.gz kernel-qcow2-util-linux-26d0c0aefde9a94f29d9850514fcbcf638eb8728.tar.xz kernel-qcow2-util-linux-26d0c0aefde9a94f29d9850514fcbcf638eb8728.zip |
libmount: add reference counting to libmount_fs
* mnt_new_fs() returns object with refcount=1
* mnt_free_fs() does not care about reference counter
* new functions mnt_ref_fs() and mnt_unref_fs()
* mnt_table_add_fs() and mnt_table_rem_fs() uses reference counter
* libmmnt_context uses reference counter for internal FS (as it could be
shared outside the context)
* backwardly incompatible change:
- FS could be deallocated after mnt_table_remove_fs()
* it's recommended to use mnt_unref_fs() after mnt_table_add_fs()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libmount/src/context.c')
-rw-r--r-- | libmount/src/context.c | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/libmount/src/context.c b/libmount/src/context.c index 12f22fc92..ea13f0d1e 100644 --- a/libmount/src/context.c +++ b/libmount/src/context.c @@ -109,7 +109,7 @@ void mnt_free_context(struct libmnt_context *cxt) * @cxt: mount context * * Resets all information in the context that is directly related to - * the latest mount (spec, source, target, mount options, ....) + * the latest mount (spec, source, target, mount options, ...). * * The match patterns, cached fstab, cached canonicalized paths and tags and * [e]uid are not reset. You have to use @@ -136,9 +136,7 @@ int mnt_reset_context(struct libmnt_context *cxt) fl = cxt->flags; - if (!(cxt->flags & MNT_FL_EXTERN_FS)) - mnt_free_fs(cxt->fs); - + mnt_unref_fs(cxt->fs); mnt_free_table(cxt->mtab); free(cxt->helper); @@ -633,8 +631,9 @@ int mnt_context_is_loopdel(struct libmnt_context *cxt) * @fs: filesystem description * * The mount context uses private @fs by default. This function allows to - * overwrite the private @fs with an external instance. Note that the external - * @fs instance is not deallocated by mnt_free_context() or mnt_reset_context(). + * overwrite the private @fs with an external instance. This function + * increments @fs reference counter (and deincrement reference counter of the + * old fs). * * The @fs will be modified by mnt_context_set_{source,target,options,fstype} * functions, If the @fs is NULL, then all current FS specific settings (source, @@ -646,10 +645,9 @@ int mnt_context_set_fs(struct libmnt_context *cxt, struct libmnt_fs *fs) { if (!cxt) return -EINVAL; - if (!(cxt->flags & MNT_FL_EXTERN_FS)) - mnt_free_fs(cxt->fs); - set_flag(cxt, MNT_FL_EXTERN_FS, fs != NULL); + mnt_ref_fs(fs); /* new */ + mnt_unref_fs(cxt->fs); /* old */ cxt->fs = fs; return 0; } @@ -669,10 +667,8 @@ struct libmnt_fs *mnt_context_get_fs(struct libmnt_context *cxt) assert(cxt); if (!cxt) return NULL; - if (!cxt->fs) { + if (!cxt->fs) cxt->fs = mnt_new_fs(); - cxt->flags &= ~MNT_FL_EXTERN_FS; - } return cxt->fs; } |