Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Leap:42.3:Update
mdadm.8927
0107-Assemble-cleanup-the-failure-path.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0107-Assemble-cleanup-the-failure-path.patch of Package mdadm.8927
From 3266dc09eeddea05b603bae53e3f80b2b47a9027 Mon Sep 17 00:00:00 2001 From: Guoqing Jiang <gqjiang@suse.com> Date: Wed, 14 Mar 2018 14:50:37 +0800 Subject: [PATCH] Assemble: cleanup the failure path Git-commit: 57908e9ebad21e9ea84d9f54684bae3af8f62604 Patch-mainline: mdadm-4.0+ References: bsc#1049126 There are some failure paths which share common codes before return, so simplify them by move common codes to the end of function, and just goto out in case failure happened. Reviewed-by: NeilBrown <neilb@suse.com> Signed-off-by: Guoqing Jiang <gqjiang@suse.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com> --- Assemble.c | 58 +++++++++++++++++++++------------------------------------- 1 file changed, 21 insertions(+), 37 deletions(-) diff --git a/Assemble.c b/Assemble.c index 688bfd6..0b979da 100644 --- a/Assemble.c +++ b/Assemble.c @@ -1297,13 +1297,13 @@ int Assemble(struct supertype *st, char *mddev, * START_ARRAY * */ - int rv; - int mdfd; + int rv = -1; + int mdfd = -1; int clean; int auto_assem = (mddev == NULL && !ident->uuid_set && ident->super_minor == UnSet && ident->name[0] == 0 && (ident->container == NULL || ident->member == NULL)); - struct devs *devices; + struct devs *devices = NULL; char *devmap; int *best = NULL; /* indexed by raid_disk */ int bestcnt = 0; @@ -1418,9 +1418,7 @@ try_again: pr_err("Found some drive for an array that is already active: %s\n", mp->path); pr_err("giving up.\n"); - if (locked == 1) - cluster_release_dlmlock(); - return 1; + goto out; } for (dv = pre_exist->devs; dv; dv = dv->next) { /* We want to add this device to our list, @@ -1493,9 +1491,7 @@ try_again: st->ss->free_super(st); if (auto_assem) goto try_again; - if (locked == 1) - cluster_release_dlmlock(); - return 1; + goto out; } mddev = chosen_name; if (get_linux_version() < 2004000 || @@ -1522,9 +1518,7 @@ try_again: st->ss->free_super(st); if (auto_assem) goto try_again; - if (locked == 1) - cluster_release_dlmlock(); - return 1; + goto out; } /* just incase it was started but has no content */ ioctl(mdfd, STOP_ARRAY, NULL); @@ -1549,9 +1543,8 @@ try_again: c, content, mdfd, mddev, &most_recent, &bestcnt, &best, inargv); if (devcnt < 0) { - if (locked == 1) - cluster_release_dlmlock(); - return 1; + mdfd = -3; + goto out; } if (devcnt == 0) { @@ -1559,10 +1552,8 @@ try_again: mddev); if (st) st->ss->free_super(st); - close(mdfd); - free(devices); free(devmap); - return 1; + goto out; } if (c->update && strcmp(c->update, "byteorder")==0) @@ -1676,25 +1667,19 @@ try_again: : (O_RDONLY|O_EXCL)))< 0) { pr_err("Cannot open %s: %s\n", devices[j].devname, strerror(errno)); - close(mdfd); - free(devices); - return 1; + goto out; } if (st->ss->load_super(st,fd, NULL)) { close(fd); pr_err("RAID superblock has disappeared from %s\n", devices[j].devname); - close(mdfd); - free(devices); - return 1; + goto out; } close(fd); } if (st->sb == NULL) { pr_err("No suitable drives found for %s\n", mddev); - close(mdfd); - free(devices); - return 1; + goto out; } st->ss->getinfo_super(st, content, NULL); #ifndef MDASSEMBLE @@ -1763,17 +1748,13 @@ try_again: if (fd < 0) { pr_err("Could not open %s for write - cannot Assemble array.\n", devices[chosen_drive].devname); - close(mdfd); - free(devices); - return 1; + goto out; } if (st->ss->store_super(st, fd)) { close(fd); pr_err("Could not re-write superblock on %s\n", devices[chosen_drive].devname); - close(mdfd); - free(devices); - return 1; + goto out; } if (c->verbose >= 0) pr_err("Marking array %s as 'clean'\n", @@ -1832,9 +1813,7 @@ try_again: pr_err("Failed to restore critical section for reshape, sorry.\n"); if (c->backup_file == NULL) cont_err("Possibly you needed to specify the --backup-file\n"); - close(mdfd); - free(devices); - return err; + goto out; } } #endif @@ -1864,6 +1843,7 @@ try_again: ioctl(mdfd, STOP_ARRAY, NULL); free(devices); map_unlock(&map); +out: if (rv == 0) { wait_for(chosen_name, mdfd); close(mdfd); @@ -1893,12 +1873,16 @@ try_again: usecs <<= 1; } } - } else + } else if (mdfd >= 0) close(mdfd); /* '2' means 'OK, but not started yet' */ if (locked == 1) cluster_release_dlmlock(); + if (rv == -1) { + free(devices); + return 1; + } return rv == 2 ? 0 : rv; } -- 2.10.0
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor