tunegfs2: Fix label/locktable setting code
This patch is aimed at fixing Red Hat bz #719135
The code here seemed a bit confused. I've added a check for the format of the locktable/label based on the same code in mkfs. In addition we set the lock proto first in order that we use the new value of the lock proto when checking the format of the lock table.
There is no need to have a separate function for setting the label to the locktable, since they are both setting the same data.
The on-disk locktable and lockproto always contain trailing NULLs and when we read the sb from disk, we now always add NULLs at the end of the strings so that we can rely on this later on.
The patch also checks the size of the lock table when it is set to ensure that it is not too large.
gfs2/tune/main.c +16 -13
@@ -20,13 +20,13 @@ struct tunegfs2 tunegfs2_struct;struct tunegfs2 *tfs = &tunegfs2_struct; -void parse_mount_options (char *arg) +static void parse_mount_options (char *arg) {struct opt_map *m;char *s, *c;int l;struct opt_map { -char *tag; +const char *tag;int *flag;char **val; } map[]= {
@@ -101,6 +101,12 @@ int main(int argc, char **argv)return EX_USAGE ; } +if (tfs->opt_label && tfs->opt_table) { +fprintf (stderr,_ ("The -L and -o locktable= options are mutually exclusive\n" )); +usage (argv[0 ]); +return EX_USAGE ; + } + tfs->devicename = argv[optind]; tfs->fd =open (tfs->devicename,O_RDWR );
@@ -120,29 +126,26 @@ int main(int argc, char **argv) goto out; } -/* Keep label and table together because they are the same field -* in the superblock */ - -if (tfs->opt_label) { - status =change_label (tfs, tfs->label); +if (tfs->opt_proto) { + status =change_lockproto (tfs, tfs->proto);if (status) goto out; } -if (tfs->opt_table) { - status =change_locktable (tfs, tfs->table); +if (tfs->opt_label) { + status =change_locktable (tfs, tfs->label);if (status) goto out; } -if (tfs->opt_proto) { - status =change_lockproto (tfs, tfs->proto); +if (tfs->opt_table) { + status =change_locktable (tfs, tfs->table);if (status) goto out; } -if (tfs->opt_label || tfs->opt_uuid || - tfs->opt_table || tfs->opt_proto) { +if (tfs->opt_label || tfs->opt_uuid || tfs->opt_table || + tfs->opt_proto) { status =write_super (tfs);if (status) goto out;
gfs2/tune/super.c +27 -53
114 lines not on this page · raw message
gfs2/tune/tunegfs2.h +0 -1
@@ -24,7 +24,6 @@ extern int print_super(const struct tunegfs2 *);extern int read_super (struct tunegfs2 *);extern int write_super (const struct tunegfs2 *);extern int change_uuid (struct tunegfs2 *,const char *uuid); -extern int change_label (struct tunegfs2 *,const char *label);extern int change_lockproto (struct tunegfs2 *,const char *label);extern int change_locktable (struct tunegfs2 *,const char *label);