summaryrefslogtreecommitdiffstats
path: root/libmount/src/tab_update.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_update.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_update.c')
-rw-r--r--libmount/src/tab_update.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/libmount/src/tab_update.c b/libmount/src/tab_update.c
index 9603f77ec..b5c92726f 100644
--- a/libmount/src/tab_update.c
+++ b/libmount/src/tab_update.c
@@ -70,7 +70,7 @@ void mnt_free_update(struct libmnt_update *upd)
DBG(UPDATE, mnt_debug_h(upd, "free"));
- mnt_free_fs(upd->fs);
+ mnt_unref_fs(upd->fs);
mnt_free_table(upd->mountinfo);
free(upd->target);
free(upd->filename);
@@ -180,7 +180,7 @@ int mnt_update_set_fs(struct libmnt_update *upd, unsigned long mountflags,
DBG(UPDATE, mnt_fs_print_debug(fs, stderr));
}
- mnt_free_fs(upd->fs);
+ mnt_unref_fs(upd->fs);
free(upd->target);
upd->ready = FALSE;
upd->fs = NULL;
@@ -350,7 +350,7 @@ static int utab_new_entry(struct libmnt_update *upd, struct libmnt_fs *fs,
return 0;
err:
free(u);
- mnt_free_fs(upd->fs);
+ mnt_unref_fs(upd->fs);
upd->fs = NULL;
return rc;
}
@@ -671,6 +671,8 @@ static int add_file_entry(struct libmnt_table *tb, struct libmnt_update *upd)
return -ENOMEM;
mnt_table_add_fs(tb, fs);
+ mnt_unref_fs(fs);
+
return update_table(upd, tb);
}
@@ -722,7 +724,6 @@ static int update_remove_entry(struct libmnt_update *upd, struct libmnt_lock *lc
if (rem) {
mnt_table_remove_fs(tb, rem);
rc = update_table(upd, tb);
- mnt_free_fs(rem);
}
}
if (lc)
@@ -905,7 +906,7 @@ static int test_add(struct libmnt_test *ts, int argc, char *argv[])
mnt_fs_set_options(fs, argv[4]);
rc = update(NULL, fs, 0);
- mnt_free_fs(fs);
+ mnt_unref_fs(fs);
return rc;
}
@@ -928,7 +929,7 @@ static int test_move(struct libmnt_test *ts, int argc, char *argv[])
rc = update(NULL, fs, MS_MOVE);
- mnt_free_fs(fs);
+ mnt_unref_fs(fs);
return rc;
}
@@ -943,7 +944,7 @@ static int test_remount(struct libmnt_test *ts, int argc, char *argv[])
mnt_fs_set_options(fs, argv[2]);
rc = update(NULL, fs, MS_REMOUNT);
- mnt_free_fs(fs);
+ mnt_unref_fs(fs);
return rc;
}
@@ -962,7 +963,9 @@ static int test_replace(struct libmnt_test *ts, int argc, char *argv[])
mnt_fs_set_source(fs, argv[1]);
mnt_fs_set_target(fs, argv[2]);
mnt_fs_append_comment(fs, "# this is new filesystem\n");
+
mnt_table_add_fs(tb, fs);
+ mnt_unref_fs(fs);
rc = mnt_table_replace_file(tb, mnt_get_fstab_path());
mnt_free_table(tb);