gfs2-utils: master - libgfs2: Remove path_name from struct gfs2_sbd
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=ec2b6270...
Commit: ec2b6270b291a671b70a17a12389d8fecaabd61b
Parent: 5d4dbd94f5244f45fb6ee01d27353a0a7a2fd6d9
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Tue Oct 7 21:23:29 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Tue Oct 7 21:23:29 2014 +0100
libgfs2: Remove path_name from struct gfs2_sbd
This is another gfs2_sbd field which needn't be kept in libgfs2. In the
gfs2_jadd case, create a new structure in which to store command
options, including the mount point path.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/libgfs2/libgfs2.h | 4 +--
gfs2/libgfs2/misc.c | 4 +-
gfs2/mkfs/main_grow.c | 9 +++----
gfs2/mkfs/main_jadd.c | 53 ++++++++++++++++++++++++-----------------------
4 files changed, 34 insertions(+), 36 deletions(-)
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 658fd4f..6509e9b 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -280,8 +280,6 @@ struct gfs2_sbd {
unsigned int rgsize; /* Size of resource groups (in MB) */
unsigned int qcsize; /* Size of quota change files (in MB) */
- char *path_name;
-
/* Constants */
uint32_t sd_fsb2bb;
@@ -679,7 +677,7 @@ extern int lgfs2_open_mnt_dev(const char *path, int flags, struct mntent **mnt);
extern int lgfs2_open_mnt_dir(const char *path, int flags, struct mntent **mnt);
extern int find_gfs2_meta(struct gfs2_sbd *sdp);
extern int dir_exists(const char *dir);
-extern int mount_gfs2_meta(struct gfs2_sbd *sdp);
+extern int mount_gfs2_meta(struct gfs2_sbd *sdp, const char *path);
extern void cleanup_metafs(struct gfs2_sbd *sdp);
extern int is_fsname(char *name);
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index a66ca4f..6feccad 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -222,7 +222,7 @@ static void sighandler(int error)
metafs_interrupted = 1;
}
-int mount_gfs2_meta(struct gfs2_sbd *sdp)
+int mount_gfs2_meta(struct gfs2_sbd *sdp, const char *path)
{
int ret;
struct sigaction sa = { .sa_handler = &sighandler };
@@ -242,7 +242,7 @@ int mount_gfs2_meta(struct gfs2_sbd *sdp)
sigaction(SIGCONT, &sa, NULL);
sigaction(SIGUSR1, &sa, NULL);
sigaction(SIGUSR2, &sa, NULL);
- ret = mount(sdp->path_name, sdp->metafs_path, "gfs2meta", 0, NULL);
+ ret = mount(path, sdp->metafs_path, "gfs2meta", 0, NULL);
if (ret) {
rmdir(sdp->metafs_path);
return -1;
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index 4c1225c..79ba56a 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -306,9 +306,9 @@ trunc:
/**
* print_info - Print out various bits of (interesting?) information
*/
-static void print_info(struct gfs2_sbd *sdp, char *device)
+static void print_info(struct gfs2_sbd *sdp, char *device, char *mnt_path)
{
- log_notice("FS: %-25s%s\n", _("Mount point:"), sdp->path_name);
+ log_notice("FS: %-25s%s\n", _("Mount point:"), mnt_path);
log_notice("FS: %-25s%s\n", _("Device:"), device);
log_notice("FS: %-25s%llu (0x%llx)\n", _("Size:"),
(unsigned long long)fssize, (unsigned long long)fssize);
@@ -352,7 +352,6 @@ void main_grow(int argc, char *argv[])
fprintf(stderr, _("%s: not a mounted gfs2 file system\n"), argv[optind]);
continue;
}
- sdp->path_name = mnt->mnt_dir;
if (lgfs2_get_dev_info(sdp->device_fd, &sdp->dinfo) < 0) {
perror(mnt->mnt_fsname);
@@ -373,7 +372,7 @@ void main_grow(int argc, char *argv[])
exit(EXIT_FAILURE);
}
fix_device_geometry(sdp);
- if (mount_gfs2_meta(sdp)) {
+ if (mount_gfs2_meta(sdp, mnt->mnt_dir)) {
perror(_("Failed to mount GFS2 meta file system"));
exit(EXIT_FAILURE);
}
@@ -429,7 +428,7 @@ void main_grow(int argc, char *argv[])
error = -1;
goto out;
}
- print_info(sdp, mnt->mnt_fsname);
+ print_info(sdp, mnt->mnt_fsname, mnt->mnt_dir);
rgcount = initialize_new_portion(sdp, rgs);
if (rgcount == 0 || metafs_interrupted)
goto out;
diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
index d468a6f..4968ec9 100644
--- a/gfs2/mkfs/main_jadd.c
+++ b/gfs2/mkfs/main_jadd.c
@@ -27,8 +27,11 @@
#define BUF_SIZE 4096
#define RANDOM(values) ((values) * (random() / (RAND_MAX + 1.0)))
-static int quiet = 0;
-static int debug = 0;
+struct jadd_opts {
+ char *path;
+ unsigned quiet:1;
+ unsigned debug:1;
+};
static void
make_jdata(int fd, const char *value)
@@ -116,7 +119,7 @@ static void print_usage(const char *prog_name)
*
*/
-static void decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp)
+static void decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp, struct jadd_opts *opts)
{
int cont = TRUE;
int optchar;
@@ -129,7 +132,7 @@ static void decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp)
sdp->qcsize = atoi(optarg);
break;
case 'D':
- debug = 1;
+ opts->debug = 1;
lgfs2_set_debug(1);
break;
case 'h':
@@ -143,7 +146,7 @@ static void decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp)
sdp->md.journals = atoi(optarg);
break;
case 'q':
- quiet = 1;
+ opts->quiet = 1;
break;
case 'V':
printf("gfs2_jadd %s (built %s %s)\n", VERSION,
@@ -166,7 +169,7 @@ static void decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp)
}
if (optind < argc) {
- sdp->path_name = argv[optind];
+ opts->path = argv[optind];
optind++;
} else
die( _("no path specified (try -h for help)\n"));
@@ -174,13 +177,13 @@ static void decode_arguments(int argc, char *argv[], struct gfs2_sbd *sdp)
if (optind < argc)
die( _("Unrecognized argument: %s\n"), argv[optind]);
- if (debug) {
+ if (opts->debug) {
printf( _("Command Line Arguments:\n"));
printf(" qcsize = %u\n", sdp->qcsize);
printf(" jsize = %u\n", sdp->jsize);
printf(" journals = %u\n", sdp->md.journals);
- printf(" quiet = %d\n", quiet);
- printf(" path = %s\n", sdp->path_name);
+ printf(" quiet = %u\n", opts->quiet);
+ printf(" path = %s\n", opts->path);
}
}
@@ -200,14 +203,14 @@ static void verify_arguments(struct gfs2_sbd *sdp)
*
*/
-static void print_results(struct gfs2_sbd *sdp)
+static void print_results(struct gfs2_sbd *sdp, struct jadd_opts *opts)
{
- if (debug)
+ if (opts->debug)
printf("\n");
- else if (quiet)
+ else if (opts->quiet)
return;
- printf( _("Filesystem: %s\n"), sdp->path_name);
+ printf( _("Filesystem: %s\n"), opts->path);
printf( _("Old Journals: %u\n"), sdp->orig_journals);
printf( _("New Journals: %u\n"), sdp->md.journals);
@@ -364,12 +367,11 @@ add_qc(struct gfs2_sbd *sdp)
}
}
-static void
-gather_info(struct gfs2_sbd *sdp)
+static void gather_info(struct gfs2_sbd *sdp, struct jadd_opts *opts)
{
struct statfs statbuf;
- if (statfs(sdp->path_name, &statbuf) < 0) {
- perror(sdp->path_name);
+ if (statfs(opts->path, &statbuf) < 0) {
+ perror(opts->path);
exit(EXIT_FAILURE);
}
sdp->bsize = statbuf.f_bsize;
@@ -485,6 +487,7 @@ add_j(struct gfs2_sbd *sdp)
void main_jadd(int argc, char *argv[])
{
+ struct jadd_opts opts = {0};
struct gfs2_sbd sbd, *sdp = &sbd;
struct mntent *mnt;
unsigned int total;
@@ -494,23 +497,21 @@ void main_jadd(int argc, char *argv[])
sdp->qcsize = GFS2_DEFAULT_QCSIZE;
sdp->md.journals = 1;
- decode_arguments(argc, argv, sdp);
+ decode_arguments(argc, argv, sdp, &opts);
verify_arguments(sdp);
- sbd.path_fd = lgfs2_open_mnt_dir(sbd.path_name, O_RDONLY|O_CLOEXEC, &mnt);
+ sbd.path_fd = lgfs2_open_mnt_dir(opts.path, O_RDONLY|O_CLOEXEC, &mnt);
if (sbd.path_fd < 0) {
- fprintf(stderr, _("Error looking up mount '%s': %s\n"), sbd.path_name, strerror(errno));
+ fprintf(stderr, _("Error looking up mount '%s': %s\n"), opts.path, strerror(errno));
exit(EXIT_FAILURE);
}
if (mnt == NULL) {
- fprintf(stderr, _("%s: not a mounted gfs2 file system\n"), sbd.path_name);
+ fprintf(stderr, _("%s: not a mounted gfs2 file system\n"), opts.path);
exit(EXIT_FAILURE);
}
- sbd.path_name = mnt->mnt_dir;
-
- gather_info(sdp);
+ gather_info(sdp, &opts);
- if (mount_gfs2_meta(sdp)) {
+ if (mount_gfs2_meta(sdp, mnt->mnt_dir)) {
perror("GFS2 metafs");
exit(EXIT_FAILURE);
}
@@ -538,5 +539,5 @@ void main_jadd(int argc, char *argv[])
close(sdp->path_fd);
cleanup_metafs(sdp);
sync();
- print_results(sdp);
+ print_results(sdp, &opts);
}
9 years, 7 months
gfs2-utils: master - libgfs2: Remove device_name from struct gfs2_sbd
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=5d4dbd94...
Commit: 5d4dbd94f5244f45fb6ee01d27353a0a7a2fd6d9
Parent: c136b342699b1a690fac1e05afb1d94b77471a43
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Tue Oct 7 20:30:08 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Tue Oct 7 20:30:08 2014 +0100
libgfs2: Remove device_name from struct gfs2_sbd
Remove this field from struct gfs2_sbd because,
* It arbitrarily limits the path length
* It bloats the struct by PATH_MAX (commonly 4096) chars
* It isn't used by libgfs2 itself
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/edit/hexedit.c | 6 ++----
gfs2/edit/savemeta.c | 3 ++-
gfs2/fsck/initialize.c | 2 +-
gfs2/libgfs2/libgfs2.h | 1 -
gfs2/mkfs/main_grow.c | 10 ++++------
gfs2/mkfs/main_jadd.c | 1 -
6 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index b316065..dd4b625 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -1000,7 +1000,7 @@ static void read_superblock(int fd)
if (!sbd.bsize)
sbd.bsize = GFS2_DEFAULT_BSIZE;
if (lgfs2_get_dev_info(fd, &sbd.dinfo)) {
- perror(sbd.device_name);
+ perror(device);
exit(-1);
}
if(compute_constants(&sbd)) {
@@ -1401,8 +1401,7 @@ uint64_t check_keywords(const char *kword)
if (sbd.gfs1)
fprintf(stderr, "This is GFS1; there's no master directory.\n");
else if (!sbd.sd_sb.sb_master_dir.no_addr) {
- fprintf(stderr, "GFS2 master directory not found on %s\n",
- sbd.device_name);
+ fprintf(stderr, "GFS2 master directory not found on %s\n", device);
exit(-1);
} else
blk = sbd.sd_sb.sb_master_dir.no_addr;
@@ -2541,7 +2540,6 @@ int main(int argc, char *argv[])
read_superblock(fd);
max_block = lseek(fd, 0, SEEK_END) / sbd.bsize;
- strcpy(sbd.device_name, device);
if (sbd.gfs1)
edit_row[GFS2_MODE]++;
else
diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c
index 5147ee5..5d30d28 100644
--- a/gfs2/edit/savemeta.c
+++ b/gfs2/edit/savemeta.c
@@ -62,6 +62,7 @@ static uint64_t journal_blocks[MAX_JOURNALS_SAVED];
static uint64_t gfs1_journal_size = 0; /* in blocks */
static int journals_found = 0;
int print_level = MSG_NOTICE;
+extern char *device;
static int block_is_a_journal(void)
{
@@ -737,7 +738,7 @@ void savemeta(char *out_fn, int saveoption, int gziplevel)
if (!sbd.gfs1)
sbd.bsize = GFS2_DEFAULT_BSIZE;
if (lgfs2_get_dev_info(sbd.device_fd, &sbd.dinfo)) {
- perror(sbd.device_name);
+ perror(device);
exit(-1);
}
fix_device_geometry(&sbd);
diff --git a/gfs2/fsck/initialize.c b/gfs2/fsck/initialize.c
index 4dedec2..4e52262 100644
--- a/gfs2/fsck/initialize.c
+++ b/gfs2/fsck/initialize.c
@@ -1608,7 +1608,7 @@ int initialize(struct gfs2_sbd *sdp, int force_check, int preen,
}
if (lgfs2_get_dev_info(sdp->device_fd, &sdp->dinfo)) {
- perror(sdp->device_name);
+ perror(opts.device);
return FSCK_ERROR;
}
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index f33b838..658fd4f 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -280,7 +280,6 @@ struct gfs2_sbd {
unsigned int rgsize; /* Size of resource groups (in MB) */
unsigned int qcsize; /* Size of quota change files (in MB) */
- char device_name[PATH_MAX];
char *path_name;
/* Constants */
diff --git a/gfs2/mkfs/main_grow.c b/gfs2/mkfs/main_grow.c
index c4f5055..4c1225c 100644
--- a/gfs2/mkfs/main_grow.c
+++ b/gfs2/mkfs/main_grow.c
@@ -305,12 +305,11 @@ trunc:
/**
* print_info - Print out various bits of (interesting?) information
- *
*/
-static void print_info(struct gfs2_sbd *sdp)
+static void print_info(struct gfs2_sbd *sdp, char *device)
{
log_notice("FS: %-25s%s\n", _("Mount point:"), sdp->path_name);
- log_notice("FS: %-25s%s\n", _("Device:"), sdp->device_name);
+ log_notice("FS: %-25s%s\n", _("Device:"), device);
log_notice("FS: %-25s%llu (0x%llx)\n", _("Size:"),
(unsigned long long)fssize, (unsigned long long)fssize);
log_notice("FS: %-25s%u (0x%x)\n", _("New resource group size:"), rgsize, rgsize);
@@ -354,10 +353,9 @@ void main_grow(int argc, char *argv[])
continue;
}
sdp->path_name = mnt->mnt_dir;
- strncpy(sdp->device_name, mnt->mnt_fsname, PATH_MAX - 1);
if (lgfs2_get_dev_info(sdp->device_fd, &sdp->dinfo) < 0) {
- perror(sdp->device_name);
+ perror(mnt->mnt_fsname);
exit(EXIT_FAILURE);
}
sdp->sd_sb.sb_bsize = GFS2_DEFAULT_BSIZE;
@@ -431,7 +429,7 @@ void main_grow(int argc, char *argv[])
error = -1;
goto out;
}
- print_info(sdp);
+ print_info(sdp, mnt->mnt_fsname);
rgcount = initialize_new_portion(sdp, rgs);
if (rgcount == 0 || metafs_interrupted)
goto out;
diff --git a/gfs2/mkfs/main_jadd.c b/gfs2/mkfs/main_jadd.c
index 4338e8d..d468a6f 100644
--- a/gfs2/mkfs/main_jadd.c
+++ b/gfs2/mkfs/main_jadd.c
@@ -507,7 +507,6 @@ void main_jadd(int argc, char *argv[])
exit(EXIT_FAILURE);
}
sbd.path_name = mnt->mnt_dir;
- strncpy(sbd.device_name, mnt->mnt_fsname, PATH_MAX - 1);
gather_info(sdp);
9 years, 7 months
gfs2-utils: master - gfs2l: Switch to lgfs2_field_assign
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=c136b342...
Commit: c136b342699b1a690fac1e05afb1d94b77471a43
Parent: f8476d931fc930444934b5eb80980b5b97bd52e4
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Tue Oct 7 13:06:28 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Tue Oct 7 13:23:25 2014 +0100
gfs2l: Switch to lgfs2_field_assign
The new lgfs2_field_assign function was based on code in gfs2l, which
can now be converted to use the new libgfs2 functions.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/libgfs2/lang.c | 78 +++++++++++++++------------------------------------
gfs2/libgfs2/meta.c | 6 +++-
2 files changed, 28 insertions(+), 56 deletions(-)
diff --git a/gfs2/libgfs2/lang.c b/gfs2/libgfs2/lang.c
index b4a743f..13333a1 100644
--- a/gfs2/libgfs2/lang.c
+++ b/gfs2/libgfs2/lang.c
@@ -471,7 +471,7 @@ invalid:
static int ast_field_set(struct gfs2_buffer_head *bh, const struct lgfs2_metafield *field,
struct ast_node *val)
{
- char *fieldp = (char *)bh->iov.iov_base + field->offset;
+ int err = 0;
if (field->flags & LGFS2_MFF_UUID) {
uint8_t uuid[16];
@@ -479,56 +479,21 @@ static int ast_field_set(struct gfs2_buffer_head *bh, const struct lgfs2_metafie
if (ret != AST_INTERP_SUCCESS)
return ret;
-
- memcpy(fieldp, uuid, 16);
- bmodified(bh);
- return AST_INTERP_SUCCESS;
+ err = lgfs2_field_assign(bh->b_data, field, uuid);
+ } else if (field->flags & LGFS2_MFF_STRING) {
+ err = lgfs2_field_assign(bh->b_data, field, val->ast_str);
+ } else {
+ err = lgfs2_field_assign(bh->b_data, field, &val->ast_num);
}
- if ((field->flags & LGFS2_MFF_STRING) && strlen(val->ast_str) > field->length) {
- fprintf(stderr, "String '%s' is too long for field '%s'\n", val->ast_str, field->name);
+ if (err) {
+ fprintf(stderr, "Invalid field assignment: %s (size %d) = %s\n",
+ field->name, field->length, val->ast_text);
return AST_INTERP_INVAL;
}
- if (field->flags & (LGFS2_MFF_STRING|LGFS2_MFF_UUID)) {
- strncpy(fieldp, val->ast_str, field->length - 1);
- fieldp[field->length - 1] = '\0';
- bmodified(bh);
- return AST_INTERP_SUCCESS;
- } else {
- // Numeric fields
- switch(field->length) {
- case 1:
- if (val->ast_num > UINT8_MAX)
- break;
- *fieldp = (uint8_t)val->ast_num;
- bmodified(bh);
- return AST_INTERP_SUCCESS;
- case 2:
- if (val->ast_num > UINT16_MAX)
- break;
- *(uint16_t *)fieldp = cpu_to_be16((uint16_t)val->ast_num);
- bmodified(bh);
- return AST_INTERP_SUCCESS;
- case 4:
- if (val->ast_num > UINT32_MAX)
- break;
- *(uint32_t *)fieldp = cpu_to_be32((uint32_t)val->ast_num);
- bmodified(bh);
- return AST_INTERP_SUCCESS;
- case 8:
- *(uint64_t *)fieldp = cpu_to_be64((uint64_t)val->ast_num);
- bmodified(bh);
- return AST_INTERP_SUCCESS;
- default:
- // This should never happen
- return AST_INTERP_ERR;
- }
- }
-
- fprintf(stderr, "Invalid field assignment: %s (size %d) = %s\n",
- field->name, field->length, val->ast_text);
- return AST_INTERP_INVAL;
+ bmodified(bh);
+ return AST_INTERP_SUCCESS;
}
static const struct lgfs2_metadata *lang_find_mtype(struct ast_node *node, struct gfs2_buffer_head *bh, unsigned ver)
@@ -558,7 +523,6 @@ static struct lgfs2_lang_result *ast_interp_set(struct lgfs2_lang_state *state,
struct ast_node *fieldspec;
struct ast_node *fieldname;
struct ast_node *fieldval;
- int i = 0;
int ret = 0;
unsigned ver = sbd->gfs1 ? LGFS2_MD_GFS1 : LGFS2_MD_GFS2;
@@ -592,17 +556,21 @@ static struct lgfs2_lang_result *ast_interp_set(struct lgfs2_lang_state *state,
for (fieldspec = lookup->ast_right;
fieldspec != NULL && fieldspec->ast_type == AST_EX_FIELDSPEC;
fieldspec = fieldspec->ast_left) {
+ const struct lgfs2_metafield *mfield;
fieldname = fieldspec->ast_right;
fieldval = fieldname->ast_right;
- for (i = 0; i < result->lr_mtype->nfields; i++) {
- if (!strcmp(result->lr_mtype->fields[i].name, fieldname->ast_str)) {
- ret = ast_field_set(result->lr_bh, &result->lr_mtype->fields[i], fieldval);
- if (ret != AST_INTERP_SUCCESS) {
- goto out_err;
- }
- break;
- }
+
+ mfield = lgfs2_find_mfield_name(fieldname->ast_str, result->lr_mtype);
+ if (mfield == NULL) {
+ fprintf(stderr, "No field '%s' found in '%s'\n",
+ fieldname->ast_str, result->lr_mtype->name);
+ goto out_err;
+ }
+
+ ret = ast_field_set(result->lr_bh, mfield, fieldval);
+ if (ret != AST_INTERP_SUCCESS) {
+ goto out_err;
}
}
diff --git a/gfs2/libgfs2/meta.c b/gfs2/libgfs2/meta.c
index f0eed3d..79de64d 100644
--- a/gfs2/libgfs2/meta.c
+++ b/gfs2/libgfs2/meta.c
@@ -901,7 +901,12 @@ int lgfs2_field_assign(char *blk, const struct lgfs2_metafield *field, const voi
return 0;
}
+ errno = EINVAL;
if (field->flags & LGFS2_MFF_STRING) {
+ size_t len = strnlen(val, field->length);
+
+ if (len >= field->length)
+ return 1;
strncpy(fieldp, val, field->length - 1);
fieldp[field->length - 1] = '\0';
return 0;
@@ -925,6 +930,5 @@ int lgfs2_field_assign(char *blk, const struct lgfs2_metafield *field, const voi
break;
}
- errno = EINVAL;
return 1;
}
9 years, 7 months
gfs2-utils: master - gfs2_edit: Use metadata description to print and assign fields
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=f8476d93...
Commit: f8476d931fc930444934b5eb80980b5b97bd52e4
Parent: d25f31ad78e5fe96e9cd7b73fc737e7f1130d55c
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Tue Oct 7 11:25:10 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Tue Oct 7 13:22:55 2014 +0100
gfs2_edit: Use metadata description to print and assign fields
Replace the large number of separate field assignment and printing
functions in gfs2_edit with the new functions in libgfs2. This reduces
the amount of code involved dramatically and fixes three coverity
complaints related to the use of the 'checkassigns' macro.
This relates to the form: gfs2_edit -p 1234 field foo [bar] /dev/baz
The 'device' variable has been changed from char[NAME_MAX] to a pointer
to an argv member, so that now we can check whether the optional [bar]
argument is missing properly, i.e. no longer assume the device path will
begin with '/'. It also means the device name is no longer limited to
255 chars.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/edit/gfs2hex.c | 1 -
gfs2/edit/hexedit.c | 465 +++++----------------------------------------------
gfs2/edit/hexedit.h | 1 -
3 files changed, 43 insertions(+), 424 deletions(-)
diff --git a/gfs2/edit/gfs2hex.c b/gfs2/edit/gfs2hex.c
index b6075f4..dc6bb8f 100644
--- a/gfs2/edit/gfs2hex.c
+++ b/gfs2/edit/gfs2hex.c
@@ -48,7 +48,6 @@ struct gfs2_sbd sbd;
uint64_t starting_blk;
struct blkstack_info blockstack[BLOCK_STACK_SIZE];
int identify = FALSE;
-char device[NAME_MAX];
uint64_t max_block = 0;
int start_row[DMODES], end_row[DMODES], lines_per_row[DMODES];
struct gfs_sb *sbd1;
diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c
index 0982f7b..b316065 100644
--- a/gfs2/edit/hexedit.c
+++ b/gfs2/edit/hexedit.c
@@ -44,291 +44,7 @@ int pgnum;
int details = 0;
long int gziplevel = 9;
static int termcols;
-
-/* for assigning numeric fields: */
-#define checkassign(strfield, struct, member, value) do { \
- if (strcmp(#member, strfield) == 0) { \
- struct->member = (typeof(struct->member)) value; \
- return 0; \
- } \
- } while(0)
-
-/* for assigning string fields: */
-#define checkassigns(strfield, struct, member, val) do { \
- if (strcmp(#member, strfield) == 0) { \
- memset(struct->member, 0, sizeof(struct->member)); \
- strncpy((char *)struct->member, (char *)val, \
- sizeof(struct->member)); \
- return 0; \
- } \
- } while(0)
-
-/* for printing numeric fields: */
-#define checkprint(strfield, struct, member) do { \
- if (strcmp(#member, strfield) == 0) { \
- if (dmode == HEX_MODE) \
- printf("0x%llx\n", \
- (unsigned long long)struct->member); \
- else \
- printf("%llu\n", \
- (unsigned long long)struct->member); \
- return 0; \
- } \
- } while(0)
-
-/* for printing string fields: */
-#define checkprints(strfield, struct, member) do { \
- if (strcmp(#member, strfield) == 0) { \
- printf("%s\n", struct->member); \
- return 0; \
- } \
- } while(0)
-
-
-/* -------------------------------------------------------------------------
- * field-related functions:
- * ------------------------------------------------------------------------- */
-static int gfs2_sb_printval(struct gfs2_sb *lsb, const char *strfield)
-{
- checkprint(strfield, lsb, sb_fs_format);
- checkprint(strfield, lsb, sb_multihost_format);
- checkprint(strfield, lsb, __pad0);
- checkprint(strfield, lsb, sb_bsize);
- checkprint(strfield, lsb, sb_bsize_shift);
- checkprint(strfield, lsb, __pad1);
- checkprint(strfield, lsb, sb_master_dir.no_addr);
- checkprint(strfield, lsb, __pad2.no_addr);
- checkprint(strfield, lsb, sb_root_dir.no_addr);
- checkprints(strfield, lsb, sb_lockproto);
- checkprints(strfield, lsb, sb_locktable);
- checkprint(strfield, lsb, __pad3.no_addr);
- checkprint(strfield, lsb, __pad4.no_addr);
-#ifdef GFS2_HAS_UUID
- if (strcmp(strfield, "sb_uuid") == 0) {
- printf("%s\n", str_uuid(lsb->sb_uuid));
- return 0;
- }
-#endif
-
- return -1;
-}
-
-static int gfs2_sb_assignval(struct gfs2_sb *lsb, const char *strfield,
- uint64_t value)
-{
- checkassign(strfield, lsb, sb_fs_format, value);
- checkassign(strfield, lsb, sb_multihost_format, value);
- checkassign(strfield, lsb, __pad0, value);
- checkassign(strfield, lsb, sb_bsize, value);
- checkassign(strfield, lsb, sb_bsize_shift, value);
- checkassign(strfield, lsb, __pad1, value);
- checkassign(strfield, lsb, sb_master_dir.no_addr, value);
- checkassign(strfield, lsb, __pad2.no_addr, value);
- checkassign(strfield, lsb, sb_root_dir.no_addr, value);
- checkassign(strfield, lsb, __pad3.no_addr, value);
- checkassign(strfield, lsb, __pad4.no_addr, value);
-
- return -1;
-}
-
-static int gfs2_sb_assigns(struct gfs2_sb *lsb, const char *strfield,
- const char *val)
-{
- checkassigns(strfield, lsb, sb_lockproto, val);
- checkassigns(strfield, lsb, sb_locktable, val);
-#ifdef GFS2_HAS_UUID
- checkassigns(strfield, lsb, sb_uuid, val);
-#endif
- return -1;
-}
-
-static int gfs2_dinode_printval(struct gfs2_dinode *dip, const char *strfield)
-{
- checkprint(strfield, dip, di_mode);
- checkprint(strfield, dip, di_uid);
- checkprint(strfield, dip, di_gid);
- checkprint(strfield, dip, di_nlink);
- checkprint(strfield, dip, di_size);
- checkprint(strfield, dip, di_blocks);
- checkprint(strfield, dip, di_atime);
- checkprint(strfield, dip, di_mtime);
- checkprint(strfield, dip, di_ctime);
- checkprint(strfield, dip, di_major);
- checkprint(strfield, dip, di_minor);
- checkprint(strfield, dip, di_goal_meta);
- checkprint(strfield, dip, di_goal_data);
- checkprint(strfield, dip, di_flags);
- checkprint(strfield, dip, di_payload_format);
- checkprint(strfield, dip, di_height);
- checkprint(strfield, dip, di_depth);
- checkprint(strfield, dip, di_entries);
- checkprint(strfield, dip, di_eattr);
-
- return -1;
-}
-
-static int gfs2_dinode_assignval(struct gfs2_dinode *dia, const char *strfield,
- uint64_t value)
-{
- checkassign(strfield, dia, di_mode, value);
- checkassign(strfield, dia, di_uid, value);
- checkassign(strfield, dia, di_gid, value);
- checkassign(strfield, dia, di_nlink, value);
- checkassign(strfield, dia, di_size, value);
- checkassign(strfield, dia, di_blocks, value);
- checkassign(strfield, dia, di_atime, value);
- checkassign(strfield, dia, di_mtime, value);
- checkassign(strfield, dia, di_ctime, value);
- checkassign(strfield, dia, di_major, value);
- checkassign(strfield, dia, di_minor, value);
- checkassign(strfield, dia, di_goal_meta, value);
- checkassign(strfield, dia, di_goal_data, value);
- checkassign(strfield, dia, di_flags, value);
- checkassign(strfield, dia, di_payload_format, value);
- checkassign(strfield, dia, di_height, value);
- checkassign(strfield, dia, di_depth, value);
- checkassign(strfield, dia, di_entries, value);
- checkassign(strfield, dia, di_eattr, value);
-
- return -1;
-}
-
-static int gfs2_rgrp_printval(struct gfs2_rgrp *rg, const char *strfield)
-{
- checkprint(strfield, rg, rg_flags);
- checkprint(strfield, rg, rg_free);
- checkprint(strfield, rg, rg_dinodes);
-
- return -1;
-}
-
-static int gfs2_rgrp_assignval(struct gfs2_rgrp *rg, const char *strfield,
- uint64_t value)
-{
- checkassign(strfield, rg, rg_flags, value);
- checkassign(strfield, rg, rg_free, value);
- checkassign(strfield, rg, rg_dinodes, value);
-
- return -1;
-}
-
-static int gfs2_leaf_printval(struct gfs2_leaf *lf, const char *strfield)
-{
- checkprint(strfield, lf, lf_depth);
- checkprint(strfield, lf, lf_entries);
- checkprint(strfield, lf, lf_dirent_format);
- checkprint(strfield, lf, lf_next);
-#ifdef GFS2_HAS_LEAF_HINTS
- checkprint(strfield, lf, lf_inode);
- checkprint(strfield, lf, lf_dist);
- checkprint(strfield, lf, lf_nsec);
- checkprint(strfield, lf, lf_sec);
- checkprints(strfield, lf, lf_reserved2);
-#else
- checkprints(strfield, lf, lf_reserved);
-#endif
-
- return -1;
-}
-
-static int gfs2_leaf_assignval(struct gfs2_leaf *lf, const char *strfield,
- uint64_t value)
-{
- checkassign(strfield, lf, lf_depth, value);
- checkassign(strfield, lf, lf_entries, value);
- checkassign(strfield, lf, lf_dirent_format, value);
- checkassign(strfield, lf, lf_next, value);
-#ifdef GFS2_HAS_LEAF_HINTS
- checkassign(strfield, lf, lf_inode, value);
- checkassign(strfield, lf, lf_dist, value);
- checkassign(strfield, lf, lf_nsec, value);
- checkassign(strfield, lf, lf_sec, value);
-#endif
-
- return -1;
-}
-
-static int gfs2_leaf_assigns(struct gfs2_leaf *lf, const char *strfield,
- const char *val)
-{
- checkassigns(strfield, lf, lf_reserved, val);
-
- return -1;
-}
-
-static int gfs2_lh_printval(struct gfs2_log_header *lh, const char *strfield)
-{
- checkprint(strfield, lh, lh_sequence);
- checkprint(strfield, lh, lh_flags);
- checkprint(strfield, lh, lh_tail);
- checkprint(strfield, lh, lh_blkno);
- checkprint(strfield, lh, lh_hash);
-
- return -1;
-}
-
-static int gfs2_lh_assignval(struct gfs2_log_header *lh, const char *strfield,
- uint64_t value)
-{
- checkassign(strfield, lh, lh_sequence, value);
- checkassign(strfield, lh, lh_flags, value);
- checkassign(strfield, lh, lh_tail, value);
- checkassign(strfield, lh, lh_blkno, value);
- checkassign(strfield, lh, lh_hash, value);
-
- return -1;
-}
-
-static int gfs2_ld_printval(struct gfs2_log_descriptor *ld,
- const char *strfield)
-{
- checkprint(strfield, ld, ld_type);
- checkprint(strfield, ld, ld_length);
- checkprint(strfield, ld, ld_data1);
- checkprint(strfield, ld, ld_data2);
- checkprints(strfield, ld, ld_reserved);
-
- return -1;
-}
-
-static int gfs2_ld_assignval(struct gfs2_log_descriptor *ld,
- const char *strfield, uint64_t value)
-{
- checkassign(strfield, ld, ld_type, value);
- checkassign(strfield, ld, ld_length, value);
- checkassign(strfield, ld, ld_data1, value);
- checkassign(strfield, ld, ld_data2, value);
-
- return -1;
-}
-
-static int gfs2_ld_assigns(struct gfs2_log_descriptor *ld,
- const char *strfield, const char *val)
-{
- checkassigns(strfield, ld, ld_reserved, val);
-
- return -1;
-}
-
-static int gfs2_qc_printval(struct gfs2_quota_change *qc,
- const char *strfield)
-{
- checkprint(strfield, qc, qc_change);
- checkprint(strfield, qc, qc_flags);
- checkprint(strfield, qc, qc_id);
-
- return -1;
-}
-
-static int gfs2_qc_assignval(struct gfs2_quota_change *qc,
- const char *strfield, uint64_t value)
-{
- checkassign(strfield, qc, qc_change, value);
- checkassign(strfield, qc, qc_flags, value);
- checkassign(strfield, qc, qc_id, value);
-
- return -1;
-}
+char *device = NULL;
/* ------------------------------------------------------------------------- */
/* erase - clear the screen */
@@ -2071,152 +1787,59 @@ static void find_change_block_alloc(int *newval)
exit(0);
}
-/* ------------------------------------------------------------------------ */
-/* process request to print a certain field from a previously pushed block */
-/* ------------------------------------------------------------------------ */
+/**
+ * process request to print a certain field from a previously pushed block
+ */
static void process_field(const char *field, const char *nstr)
{
uint64_t fblock;
struct gfs2_buffer_head *rbh;
int type;
- struct gfs2_rgrp rg;
- struct gfs2_leaf leaf;
- struct gfs2_sb lsb;
- struct gfs2_log_header lh;
- struct gfs2_log_descriptor ld;
- struct gfs2_quota_change qc;
- int setval = 0, setstring = 0;
- uint64_t newval = 0;
-
- if (nstr[0] == '/') {
- setval = 0;
- } else if (nstr[0] == '0' && nstr[1] == 'x') {
- sscanf(nstr, "%"SCNx64, &newval);
- setval = 1;
- } else {
- newval = (uint64_t)atoll(nstr);
- setval = 1;
- }
- if (setval && newval == 0 && nstr[0] != '0')
- setstring = 1;
+ const struct lgfs2_metadata *mtype;
+ const struct lgfs2_metafield *mfield;
+
fblock = blockstack[blockhist % BLOCK_STACK_SIZE].block;
rbh = bread(&sbd, fblock);
type = get_block_type(rbh, NULL);
- switch (type) {
- case GFS2_METATYPE_SB:
- gfs2_sb_in(&lsb, rbh);
- if (setval) {
- if (setstring)
- gfs2_sb_assigns(&lsb, field, nstr);
- else
- gfs2_sb_assignval(&lsb, field, newval);
- gfs2_sb_out(&lsb, rbh->b_data);
- bmodified(rbh);
- if (!termlines)
- gfs2_sb_printval(&lsb, field);
- } else {
- if (!termlines && gfs2_sb_printval(&lsb, field))
- printf("Field '%s' not found.\n", field);
- }
- break;
- case GFS2_METATYPE_RG:
- gfs2_rgrp_in(&rg, rbh);
- if (setval) {
- gfs2_rgrp_assignval(&rg, field, newval);
- gfs2_rgrp_out_bh(&rg, rbh);
- if (!termlines)
- gfs2_rgrp_printval(&rg, field);
- } else {
- if (!termlines && gfs2_rgrp_printval(&rg, field))
- printf("Field '%s' not found.\n", field);
- }
- break;
- case GFS2_METATYPE_RB:
- if (!termlines)
- print_block_type(fblock, type,
- " which is not implemented");
- break;
- case GFS2_METATYPE_DI:
- gfs2_dinode_in(&di, rbh);
- if (setval) {
- gfs2_dinode_assignval(&di, field, newval);
- gfs2_dinode_out(&di, rbh);
- if (!termlines)
- gfs2_dinode_printval(&di, field);
- } else {
- if (!termlines && gfs2_dinode_printval(&di, field))
- printf("Field '%s' not found.\n", field);
- }
- break;
- case GFS2_METATYPE_IN:
- if (!setval && !setstring)
- print_block_type(fblock, type,
- " which is not implemented");
- break;
- case GFS2_METATYPE_LF:
- gfs2_leaf_in(&leaf, rbh);
- if (setval) {
- if (setstring)
- gfs2_leaf_assigns(&leaf, field, nstr);
- else
- gfs2_leaf_assignval(&leaf, field, newval);
- gfs2_leaf_out(&leaf, rbh);
- if (!termlines)
- gfs2_leaf_printval(&leaf, field);
- } else {
- if (!termlines && gfs2_leaf_printval(&leaf, field))
- printf("Field '%s' not found.\n", field);
- }
- break;
- case GFS2_METATYPE_LH:
- gfs2_log_header_in(&lh, rbh);
- if (setval) {
- gfs2_lh_assignval(&lh, field, newval);
- gfs2_log_header_out(&lh, rbh);
- if (!termlines)
- gfs2_lh_printval(&lh, field);
+
+ mtype = lgfs2_find_mtype(type, sbd.gfs1 ? LGFS2_MD_GFS1 : LGFS2_MD_GFS2);
+ if (mtype == NULL) {
+ fprintf(stderr, "Metadata type '%d' invalid\n", type);
+ exit(1);
+ }
+
+ mfield = lgfs2_find_mfield_name(field, mtype);
+ if (mfield == NULL) {
+ fprintf(stderr, "No field '%s' in block type '%s'\n", field, mtype->name);
+ exit(1);
+ }
+
+ if (nstr != device) {
+ int err = 0;
+ if (mfield->flags & (LGFS2_MFF_UUID|LGFS2_MFF_STRING)) {
+ err = lgfs2_field_assign(rbh->b_data, mfield, nstr);
} else {
- if (!termlines && gfs2_lh_printval(&lh, field))
- printf("Field '%s' not found.\n", field);
- }
- break;
- case GFS2_METATYPE_LD:
- gfs2_log_descriptor_in(&ld, rbh);
- if (setval) {
- if (setstring)
- gfs2_ld_assigns(&ld, field, nstr);
+ uint64_t val = 0;
+ err = sscanf(nstr, "%"SCNi64, &val);
+ if (err == 1)
+ err = lgfs2_field_assign(rbh->b_data, mfield, &val);
else
- gfs2_ld_assignval(&ld, field, newval);
- gfs2_log_descriptor_out(&ld, rbh);
- if (!termlines)
- gfs2_ld_printval(&ld, field);
- } else {
- if (!termlines && gfs2_ld_printval(&ld, field))
- printf("Field '%s' not found.\n", field);
+ err = -1;
}
- break;
- case GFS2_METATYPE_QC:
- gfs2_quota_change_in(&qc, rbh);
- if (setval) {
- gfs2_qc_assignval(&qc, field, newval);
- gfs2_quota_change_out(&qc, rbh);
- if (!termlines)
- gfs2_qc_printval(&qc, field);
- } else {
- if (!termlines && gfs2_qc_printval(&qc, field))
- printf("Field '%s' not found.\n", field);
+ if (err != 0) {
+ fprintf(stderr, "Could not set '%s' to '%s': %s\n", field, nstr,
+ strerror(errno));
+ exit(1);
}
- break;
- case GFS2_METATYPE_JD: /* journaled data */
- case GFS2_METATYPE_EA: /* extended attribute */
- case GFS2_METATYPE_ED: /* extended attribute */
- case GFS2_METATYPE_LB:
- default:
- if (!termlines)
- print_block_type(fblock, type,
- " which is not implemented");
- break;
+ bmodified(rbh);
}
+
+ if (!termlines) {
+ char str[GFS2_LOCKNAME_LEN] = "";
+ lgfs2_field_str(str, GFS2_LOCKNAME_LEN, rbh->b_data, mfield, (dmode == HEX_MODE));
+ printf("%s\n", str);
+ }
+
brelse(rbh);
fsync(sbd.device_fd);
exit(0);
@@ -2681,9 +2304,8 @@ static void parameterpass1(int argc, char *argv[], int i)
termlines = 0;
else if (!strcasecmp(argv[i], "-x"))
dmode = HEX_MODE;
- else if (!device[0] && strchr(argv[i],'/')) {
- strncpy(device, argv[i], NAME_MAX-1);
- device[NAME_MAX-1] = '\0';
+ else if (device == NULL && strchr(argv[i],'/')) {
+ device = argv[i];
}
}
@@ -2907,7 +2529,6 @@ int main(int argc, char *argv[])
edit_row[GFS2_MODE] = 10; /* Start off at root inode
pointer in superblock */
- memset(device, 0, sizeof(device));
termlines = 30; /* assume interactive mode until we find -p */
process_parameters(argc, argv, 0);
if (dmode == INIT_MODE)
diff --git a/gfs2/edit/hexedit.h b/gfs2/edit/hexedit.h
index f23c581..3e9ff5f 100644
--- a/gfs2/edit/hexedit.h
+++ b/gfs2/edit/hexedit.h
@@ -57,7 +57,6 @@ extern struct gfs2_dinode di;
extern int screen_chunk_size; /* how much of the 4K can fit on screen */
extern int gfs2_struct_type;
extern uint64_t block_in_mem;
-extern char device[NAME_MAX];
extern int identify;
extern int color_scheme;
extern WINDOW *wind;
9 years, 7 months
gfs2-utils: master - libgfs2: Add generic field assignment and print functions
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=d25f31ad...
Commit: d25f31ad78e5fe96e9cd7b73fc737e7f1130d55c
Parent: 1b27340e8afd3eea8d746c31ae461ce35145de36
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Tue Oct 7 11:19:18 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Tue Oct 7 13:22:42 2014 +0100
libgfs2: Add generic field assignment and print functions
Add lgfs2_field_str() to convert the value of any metadata field to a
string, and lgfs2_field_assign() to assign any metadata field a value.
lgfs2_find_mfield_name() is also added to make it easier to look up a
lgfs2_metafield by its name.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/libgfs2/libgfs2.h | 3 ++
gfs2/libgfs2/meta.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 87 insertions(+), 0 deletions(-)
diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index 604a7de..f33b838 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -372,6 +372,9 @@ extern const unsigned lgfs2_ld1_type_size;
extern int lgfs2_selfcheck(void);
extern const struct lgfs2_metadata *lgfs2_find_mtype(uint32_t mh_type, const unsigned versions);
extern const struct lgfs2_metadata *lgfs2_find_mtype_name(const char *name, const unsigned versions);
+extern const struct lgfs2_metafield *lgfs2_find_mfield_name(const char *name, const struct lgfs2_metadata *mtype);
+extern int lgfs2_field_str(char *str, const size_t size, const char *blk, const struct lgfs2_metafield *field, int hex);
+extern int lgfs2_field_assign(char *blk, const struct lgfs2_metafield *field, const void *val);
/* block_list.c */
diff --git a/gfs2/libgfs2/meta.c b/gfs2/libgfs2/meta.c
index 4305393..f0eed3d 100644
--- a/gfs2/libgfs2/meta.c
+++ b/gfs2/libgfs2/meta.c
@@ -734,6 +734,19 @@ const struct lgfs2_metadata lgfs2_metadata[] = {
const unsigned lgfs2_metadata_size = ARRAY_SIZE(lgfs2_metadata);
+const struct lgfs2_metafield *lgfs2_find_mfield_name(const char *name, const struct lgfs2_metadata *mtype)
+{
+ int j;
+ const struct lgfs2_metafield *f;
+
+ for (j = 0; j < mtype->nfields; j++) {
+ f = &mtype->fields[j];
+ if (strcmp(f->name, name) == 0)
+ return f;
+ }
+ return NULL;
+}
+
static int check_metadata_sizes(void)
{
unsigned offset;
@@ -844,3 +857,74 @@ const struct lgfs2_metadata *lgfs2_find_mtype_name(const char *name, const unsig
return NULL;
}
+
+int lgfs2_field_str(char *str, const size_t size, const char *blk, const struct lgfs2_metafield *field, int hex)
+{
+ const char *fieldp = blk + field->offset;
+
+ errno = EINVAL;
+ if (str == NULL)
+ return 1;
+
+ if (field->flags & LGFS2_MFF_UUID) {
+ snprintf(str, size, "%s", str_uuid((unsigned char *)fieldp));
+ } else if (field->flags & LGFS2_MFF_STRING) {
+ snprintf(str, size, "%s", fieldp);
+ } else {
+ switch(field->length) {
+ case sizeof(uint8_t):
+ snprintf(str, size, hex? "%"PRIx8 : "%"PRIu8, *(uint8_t *)fieldp);
+ break;
+ case sizeof(uint16_t):
+ snprintf(str, size, hex? "%"PRIx16 : "%"PRIu16, be16_to_cpu(*(uint16_t *)fieldp));
+ break;
+ case sizeof(uint32_t):
+ snprintf(str, size, hex? "%"PRIx32 : "%"PRIu32, be32_to_cpu(*(uint32_t *)fieldp));
+ break;
+ case sizeof(uint64_t):
+ snprintf(str, size, hex? "%"PRIx64 : "%"PRIu64, be64_to_cpu(*(uint64_t *)fieldp));
+ break;
+ default:
+ break;
+ }
+ }
+ str[size - 1] = '\0';
+ return 0;
+}
+
+int lgfs2_field_assign(char *blk, const struct lgfs2_metafield *field, const void *val)
+{
+ char *fieldp = blk + field->offset;
+
+ if (field->flags & LGFS2_MFF_UUID) {
+ memcpy(fieldp, val, 16);
+ return 0;
+ }
+
+ if (field->flags & LGFS2_MFF_STRING) {
+ strncpy(fieldp, val, field->length - 1);
+ fieldp[field->length - 1] = '\0';
+ return 0;
+ }
+
+ switch(field->length) {
+ case sizeof(uint8_t):
+ *fieldp = *(uint8_t *)val;
+ return 0;
+ case sizeof(uint16_t):
+ *(uint16_t *)fieldp = cpu_to_be16(*(uint16_t *)val);
+ return 0;
+ case sizeof(uint32_t):
+ *(uint32_t *)fieldp = cpu_to_be32(*(uint32_t *)val);
+ return 0;
+ case sizeof(uint64_t):
+ *(uint64_t *)fieldp = cpu_to_be64(*(uint64_t *)val);
+ return 0;
+ default:
+ /* Will never happen */
+ break;
+ }
+
+ errno = EINVAL;
+ return 1;
+}
9 years, 7 months
gfs2-utils: master - mkfs.gfs2: Terminate lockproto and locktable strings explicitly
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=1b27340e...
Commit: 1b27340e8afd3eea8d746c31ae461ce35145de36
Parent: bfd21b2144184a4cdf3628599152a5dbe1c3d0ab
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Mon Oct 6 14:22:16 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Mon Oct 6 14:22:16 2014 +0100
mkfs.gfs2: Terminate lockproto and locktable strings explicitly
Although the length of the lockproto and locktable options are checked
in test_locking() already, coverity still complains about our use of
strcpy here, and it can't hurt to be a bit more defensive in our string
handling so switch to strncpy and terminate the strings explicitly.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/mkfs/main_mkfs.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/gfs2/mkfs/main_mkfs.c b/gfs2/mkfs/main_mkfs.c
index e927d82..90ad4d9 100644
--- a/gfs2/mkfs/main_mkfs.c
+++ b/gfs2/mkfs/main_mkfs.c
@@ -966,8 +966,10 @@ void main_mkfs(int argc, char *argv[])
build_root(&sbd);
sb.sb_root_dir = sbd.md.rooti->i_di.di_num;
- strcpy(sb.sb_lockproto, opts.lockproto);
- strcpy(sb.sb_locktable, opts.locktable);
+ strncpy(sb.sb_lockproto, opts.lockproto, GFS2_LOCKNAME_LEN);
+ strncpy(sb.sb_locktable, opts.locktable, GFS2_LOCKNAME_LEN);
+ sb.sb_lockproto[GFS2_LOCKNAME_LEN - 1] = '\0';
+ sb.sb_locktable[GFS2_LOCKNAME_LEN - 1] = '\0';
do_init_inum(&sbd);
do_init_statfs(&sbd);
9 years, 7 months
gfs2-utils: master - fsck.gfs2: Remove dead code from scan_inode_list
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=bfd21b21...
Commit: bfd21b2144184a4cdf3628599152a5dbe1c3d0ab
Parent: 53d8c671e58f471417584e0a68eb49d32afaa295
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Mon Oct 6 13:41:17 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Mon Oct 6 13:41:17 2014 +0100
fsck.gfs2: Remove dead code from scan_inode_list
Spotted by coverity: At condition "ii = (struct inode_info *)tmp", the
value of "ii" cannot be "NULL".
In other words, tmp cannot be NULL here because the loop would have
ended in that case. Remove the NULL check and the overly excited error
message.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/fsck/pass4.c | 5 +----
1 files changed, 1 insertions(+), 4 deletions(-)
diff --git a/gfs2/fsck/pass4.c b/gfs2/fsck/pass4.c
index 7b3cb87..f9d08dc 100644
--- a/gfs2/fsck/pass4.c
+++ b/gfs2/fsck/pass4.c
@@ -55,10 +55,7 @@ static int scan_inode_list(struct gfs2_sbd *sdp) {
if (skip_this_pass || fsck_abort) /* if asked to skip the rest */
return 0;
next = osi_next(tmp);
- if (!(ii = (struct inode_info *)tmp)) {
- log_crit( _("osi_tree broken in scan_info_list!!\n"));
- exit(FSCK_ERROR);
- }
+ ii = (struct inode_info *)tmp;
/* Don't check reference counts on the special gfs files */
if (sdp->gfs1 &&
((ii->di_num.no_addr == sdp->md.riinode->i_di.di_num.no_addr) ||
9 years, 7 months
gfs2-utils: master - libgfs2: Fix check for O_RDONLY
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=53d8c671...
Commit: 53d8c671e58f471417584e0a68eb49d32afaa295
Parent: 7dcfbae20b74aa10fc597441a0538f654a13891b
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Mon Oct 6 12:44:49 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Mon Oct 6 13:21:09 2014 +0100
libgfs2: Fix check for O_RDONLY
Spotted by coverity: Execution cannot reach this statement "i->readonly
= 1U;"
This is due to a broken bitwise check for O_RDONLY which is 0 on Linux.
Use O_ACCMODE to mask out the access mode and check it properly.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/libgfs2/device_geometry.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/gfs2/libgfs2/device_geometry.c b/gfs2/libgfs2/device_geometry.c
index 27e846d..1303f11 100644
--- a/gfs2/libgfs2/device_geometry.c
+++ b/gfs2/libgfs2/device_geometry.c
@@ -53,7 +53,7 @@ int lgfs2_get_dev_info(int fd, struct lgfs2_dev_info *i)
case S_IFREG:
i->size = i->stat.st_size;
ret = fcntl(fd, F_GETFL, 0);
- if (ret & O_RDONLY)
+ if ((ret & O_ACCMODE) == O_RDONLY)
i->readonly = 1;
i->io_optimal_size = i->stat.st_blksize;
goto size_check;
9 years, 7 months
gfs2-utils: master - libgfs2: Fail fd comparison if the fds are negative
by Andrew Price
Gitweb: http://git.fedorahosted.org/git/?p=gfs2-utils.git;a=commitdiff;h=7dcfbae2...
Commit: 7dcfbae20b74aa10fc597441a0538f654a13891b
Parent: d3743efabda1118a54beb84e43655809f64a103d
Author: Andrew Price <anprice(a)redhat.com>
AuthorDate: Fri Oct 3 16:51:26 2014 +0100
Committer: Andrew Price <anprice(a)redhat.com>
CommitterDate: Fri Oct 3 16:56:42 2014 +0100
libgfs2: Fail fd comparison if the fds are negative
Spotted by coverity: "*devfd" is passed to a parameter that cannot be
negative.
This refers to the fstat calls in fdcmp. Guard them with a check for
negative fds.
Signed-off-by: Andrew Price <anprice(a)redhat.com>
---
gfs2/libgfs2/misc.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index 9eca24c..a66ca4f 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -105,6 +105,9 @@ int compute_constants(struct gfs2_sbd *sdp)
static int fdcmp(int fd1, int fd2)
{
struct stat st1, st2;
+
+ if (fd1 < 0 || fd2 < 0)
+ return -1;
if ((fstat(fd1, &st1) != 0) || (fstat(fd2, &st2) != 0))
return -1;
if (S_ISBLK(st1.st_mode) && S_ISBLK(st2.st_mode)) {
9 years, 7 months
fence-agents: master - fence_wti: Fix invalid "eol"
by Marek Grác
Gitweb: http://git.fedorahosted.org/git/?p=fence-agents.git;a=commitdiff;h=d3d73e...
Commit: d3d73eaa39dd49cc7fbc93b267daa7f51b1c5fff
Parent: 11def0b2e4dcd18c5f098ba6a4cb935af937784e
Author: Marek 'marx' Grac <mgrac(a)redhat.com>
AuthorDate: Thu Oct 2 16:20:59 2014 +0200
Committer: Marek 'marx' Grac <mgrac(a)redhat.com>
CommitterDate: Thu Oct 2 16:20:59 2014 +0200
fence_wti: Fix invalid "eol"
Fence agent for WTI does not use standard telnet login because it is possible that username/password are not
required. EOL is set by fence_login() function that is not used, so we set it manually and replace
obsolete combination of send (+eol) to correct send_eol()
Resolves: rhbz#1148762
---
fence/agents/wti/fence_wti.py | 14 ++++++++------
1 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/fence/agents/wti/fence_wti.py b/fence/agents/wti/fence_wti.py
index 78cd4e1..86f9a4d 100644
--- a/fence/agents/wti/fence_wti.py
+++ b/fence/agents/wti/fence_wti.py
@@ -27,7 +27,7 @@ BUILD_DATE="March, 2008"
def get_listing(conn, options, listing_command):
listing = ""
- conn.send(listing_command + "\r\n")
+ conn.send_eol(listing_command)
if isinstance(options["--command-prompt"], list):
re_all = list(options["--command-prompt"])
@@ -39,7 +39,7 @@ def get_listing(conn, options, listing_command):
result = conn.log_expect(options, re_all, int(options["--shell-timeout"]))
listing = conn.before
if result == (len(re_all) - 1):
- conn.send("\r\n")
+ conn.send_eol("")
conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
listing += conn.before
@@ -174,7 +174,7 @@ def set_power_status(conn, options):
'off': "/off"
}[options["--action"]]
- conn.send(action + " " + options["--plug"] + ",y\r\n")
+ conn.send_eol(action + " " + options["--plug"] + ",y")
conn.log_expect(options, options["--command-prompt"], int(options["--power-timeout"]))
def main():
@@ -207,6 +207,8 @@ is running because the connection will block any necessary fencing actions."
if options["--action"] in ["off", "reboot"]:
time.sleep(int(options["--delay"]))
+ options["eol"] = "\r\n"
+
conn = fspawn(options, TELNET_PATH)
conn.send("set binary\n")
conn.send("open %s -%s\n"%(options["--ip"], options["--ipport"]))
@@ -217,14 +219,14 @@ is running because the connection will block any necessary fencing actions."
result = conn.log_expect(options, [re_login, "Password: ", re_prompt], int(options["--shell-timeout"]))
if result == 0:
if options.has_key("--username"):
- conn.send(options["--username"]+"\r\n")
+ conn.send_eol(options["--username"])
result = conn.log_expect(options, [re_login, "Password: ", re_prompt], int(options["--shell-timeout"]))
else:
fail_usage("Failed: You have to set login name")
if result == 1:
if options.has_key("--password"):
- conn.send(options["--password"]+"\r\n")
+ conn.send_eol(options["--password"])
conn.log_expect(options, options["--command-prompt"], int(options["--shell-timeout"]))
else:
fail_usage("Failed: You have to enter password or password script")
@@ -236,7 +238,7 @@ is running because the connection will block any necessary fencing actions."
conn = fence_login(options)
result = fence_action(conn, options, set_power_status, get_power_status, get_power_status)
- fence_logout(conn, "/X\r\n")
+ fence_logout(conn, "/X")
sys.exit(result)
if __name__ == "__main__":
9 years, 7 months