[Ocfs2-tools-devel] [PATCH 1/1] Add a new method for exclusive
option check in tunefs.ocfs2.
Tao Ma
tao.ma at oracle.com
Tue Nov 6 01:00:42 PST 2007
In tunefs.ocfs2, we often have some exclusive options that can't
be done with others, and it is tedious when a new exclusive option
is going to be added since all other option checks have to be
modified accordingly.
So add a new method for this type of check so that any future
exclusive check will not touch those codes any more.
Signed-off-by: Tao Ma <tao.ma at oracle.com>
---
tunefs.ocfs2/remove_slot.c | 5 +--
tunefs.ocfs2/tunefs.c | 56 ++++++++++++++++++++++++++++++++++++-------
tunefs.ocfs2/tunefs.h | 11 ++++----
3 files changed, 55 insertions(+), 17 deletions(-)
diff --git a/tunefs.ocfs2/remove_slot.c b/tunefs.ocfs2/remove_slot.c
index 1e4238a..6da215d 100644
--- a/tunefs.ocfs2/remove_slot.c
+++ b/tunefs.ocfs2/remove_slot.c
@@ -755,9 +755,8 @@ errcode_t remove_slot_check(ocfs2_filesys *fs)
/* we don't allow remove_slot to coexist with other tunefs
* options to keep things simple.
*/
- if (opts.backup_super ||opts.vol_label ||
- opts.mount || opts.jrnl_size || opts.num_blocks ||
- opts.list_sparse || opts.feature_string) {
+ if (exclusive_option_check((char *)&opts.num_slots,
+ sizeof(opts.num_slots))) {
com_err(opts.progname, 0, "Cannot remove slot"
" along with other tasks");
exit(1);
diff --git a/tunefs.ocfs2/tunefs.c b/tunefs.ocfs2/tunefs.c
index cf01110..9752192 100644
--- a/tunefs.ocfs2/tunefs.c
+++ b/tunefs.ocfs2/tunefs.c
@@ -324,9 +324,8 @@ static void get_options(int argc, char **argv)
* options to keep things simple.
*/
if (opts.backup_super &&
- (opts.vol_label || opts.num_slots ||
- opts.mount || opts.jrnl_size || resize ||
- opts.list_sparse || opts.feature_string)) {
+ exclusive_option_check((char *)&opts.backup_super,
+ sizeof(opts.backup_super))) {
com_err(opts.progname, 0, "Cannot backup superblock"
" along with other tasks");
exit(1);
@@ -346,9 +345,8 @@ static void get_options(int argc, char **argv)
* options to keep things simple.
*/
if (opts.list_sparse &&
- (opts.vol_label || opts.num_slots ||
- opts.mount || opts.jrnl_size || resize || opts.backup_super ||
- opts.feature_string)) {
+ exclusive_option_check((char *)&opts.list_sparse,
+ sizeof(opts.list_sparse))) {
com_err(opts.progname, 0, "Cannot list sparse files"
" along with other tasks");
exit(1);
@@ -359,9 +357,8 @@ static void get_options(int argc, char **argv)
* options to keep things simple.
*/
if (opts.feature_string &&
- (opts.vol_label || opts.num_slots ||
- opts.mount || opts.jrnl_size || resize || opts.backup_super ||
- opts.list_sparse)) {
+ exclusive_option_check((char *)&opts.feature_string,
+ sizeof(opts.feature_string))) {
com_err(opts.progname, 0, "Cannot modify fs features"
" along with other tasks");
exit(1);
@@ -1738,3 +1735,44 @@ close:
return ret;
}
+
+/*
+ * Some tasks of tunefs.ocfs2 can't be coexist with other options,
+ * so they are exclusive. Check whether they are other options
+ * initalized during get_options.
+ *
+ * NOTE:
+ * 1. opts must be memset to 0 for this function and actually it is.
+ * 2. there are some fields in opts that are not options, so remove
+ * them from the check.
+ * 3. This function can't be used to check resize since it isn't a
+ * number of opts.
+ */
+errcode_t exclusive_option_check(char *para, int size)
+{
+ int start;
+ int len = sizeof(opts);
+ char *content = NULL;
+
+ if (resize)
+ return 1;
+
+ /* We check from this field of opts. */
+ start = (char *)&opts.num_slots - (char *)&opts;
+ content = (char *)&opts.num_slots;
+ while (start < len) {
+ if (content == para) {
+ content += size;
+ start += size;
+ continue;
+ }
+
+ if (*content)
+ return 1;
+
+ content++;
+ start++;
+ }
+
+ return 0;
+}
diff --git a/tunefs.ocfs2/tunefs.h b/tunefs.ocfs2/tunefs.h
index 23bab70..f88435c 100644
--- a/tunefs.ocfs2/tunefs.h
+++ b/tunefs.ocfs2/tunefs.h
@@ -78,18 +78,18 @@ enum {
};
typedef struct _ocfs2_tune_opts {
+ char *progname;
+ char *device;
+ int prompt;
+ int verbose;
+ int quiet;
uint16_t num_slots;
uint64_t num_blocks;
uint64_t jrnl_size;
char *vol_label;
- char *progname;
- char *device;
unsigned char *vol_uuid;
char *queryfmt;
int mount;
- int verbose;
- int quiet;
- int prompt;
int backup_super;
int list_sparse;
fs_options set_feature;
@@ -99,6 +99,7 @@ typedef struct _ocfs2_tune_opts {
int fd;
} ocfs2_tune_opts;
+errcode_t exclusive_option_check(char *para, int size);
void print_query(char *queryfmt);
errcode_t remove_slots(ocfs2_filesys *fs);
--
1.5.3.2.g4f337
More information about the Ocfs2-tools-devel
mailing list