summaryrefslogtreecommitdiffstats
path: root/libmount/src/tab_diff.c
diff options
context:
space:
mode:
authorKarel Zak2013-08-21 12:31:43 +0200
committerKarel Zak2013-08-21 12:48:42 +0200
commit26d0c0aefde9a94f29d9850514fcbcf638eb8728 (patch)
treecfe01b73d0d399baeeb5bdf1ffb8e6cdd6a38708 /libmount/src/tab_diff.c
parentpylibmount: remove Context_get_table() (diff)
downloadkernel-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/tab_diff.c')
-rw-r--r--libmount/src/tab_diff.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/libmount/src/tab_diff.c b/libmount/src/tab_diff.c
index 0ebdc1110..71ef0f419 100644
--- a/libmount/src/tab_diff.c
+++ b/libmount/src/tab_diff.c
@@ -54,6 +54,8 @@ static void free_tabdiff_entry(struct tabdiff_entry *de)
if (!de)
return;
list_del(&de->changes);
+ mnt_unref_fs(de->new_fs);
+ mnt_unref_fs(de->old_fs);
free(de);
}
@@ -135,6 +137,9 @@ static int tabdiff_reset(struct libmnt_tabdiff *df)
list_del(&de->changes);
list_add_tail(&de->changes, &df->unused);
+ mnt_unref_fs(de->new_fs);
+ mnt_unref_fs(de->old_fs);
+
de->new_fs = de->old_fs = NULL;
de->oper = 0;
}
@@ -164,6 +169,12 @@ static int tabdiff_add_entry(struct libmnt_tabdiff *df, struct libmnt_fs *old,
INIT_LIST_HEAD(&de->changes);
+ mnt_ref_fs(new);
+ mnt_ref_fs(old);
+
+ mnt_unref_fs(de->new_fs);
+ mnt_unref_fs(de->old_fs);
+
de->old_fs = old;
de->new_fs = new;
de->oper = oper;
@@ -280,6 +291,8 @@ int mnt_diff_tables(struct libmnt_tabdiff *df, struct libmnt_table *old_tab,
de = tabdiff_get_mount(df, src, mnt_fs_get_id(fs));
if (de) {
+ mnt_ref_fs(fs);
+ mnt_unref_fs(de->old_fs);
de->oper = MNT_TABDIFF_MOVE;
de->old_fs = fs;
} else