Rather than have the caller inspect the returned content, return an
error code from sysfs_init(). In addition make all callers actually
check it.
Signed-off-by: Jes Sorensen <Jes.Sorensen@gmail.com>
}
st->ss->getinfo_super(st, content, NULL);
#ifndef MDASSEMBLE
}
st->ss->getinfo_super(st, content, NULL);
#ifndef MDASSEMBLE
- sysfs_init(content, mdfd, NULL);
+ if (sysfs_init(content, mdfd, NULL)) {
+ pr_err("Unable to initialize sysfs\n");
+ close(mdfd);
+ free(devices);
+ return 1;
+ }
#endif
/* after reload context, store journal_clean in context */
content->journal_clean = journal_clean;
#endif
/* after reload context, store journal_clean in context */
content->journal_clean = journal_clean;
- sysfs_init(content, mdfd, NULL);
+ if (sysfs_init(content, mdfd, NULL)) {
+ pr_err("Unable to initialize sysfs\n");
+ return 1;
+ }
sra = sysfs_read(mdfd, NULL, GET_VERSION|GET_DEVS);
if (sra == NULL || strcmp(sra->text_version, content->text_version) != 0) {
sra = sysfs_read(mdfd, NULL, GET_VERSION|GET_DEVS);
if (sra == NULL || strcmp(sra->text_version, content->text_version) != 0) {
total_slots = info.array.nr_disks;
st->ss->getinfo_super(st, &info, NULL);
total_slots = info.array.nr_disks;
st->ss->getinfo_super(st, &info, NULL);
- sysfs_init(&info, mdfd, NULL);
+ if (sysfs_init(&info, mdfd, NULL)) {
+ pr_err("unable to initialize sysfs\n");
+ goto abort_locked;
+ }
if (did_default && c->verbose >= 0) {
if (is_subarray(info.text_version)) {
if (did_default && c->verbose >= 0) {
if (is_subarray(info.text_version)) {
- sysfs_init(&info, mdfd, NULL);
+ if (sysfs_init(&info, mdfd, NULL)) {
+ pr_err("unable to initialize sysfs\n");
+ goto abort_locked;
+ }
if (st->ss->external && st->container_devnm[0]) {
/* member */
if (st->ss->external && st->container_devnm[0]) {
/* member */
}
if (offset_setable) {
st->ss->getinfo_super(st, mdi, NULL);
}
if (offset_setable) {
st->ss->getinfo_super(st, mdi, NULL);
- sysfs_init(mdi, fd, NULL);
+ if (sysfs_init(mdi, fd, NULL)) {
+ pr_err("failed to intialize sysfs.\n");
+ free(mdi);
+ }
rv = sysfs_set_num_signed(mdi, NULL, "bitmap/location",
mdi->bitmap_offset);
free(mdi);
rv = sysfs_set_num_signed(mdi, NULL, "bitmap/location",
mdi->bitmap_offset);
free(mdi);
memset(&info, 0, sizeof(info));
info.array = array;
memset(&info, 0, sizeof(info));
info.array = array;
- sysfs_init(&info, fd, NULL);
+ if (sysfs_init(&info, fd, NULL)) {
+ pr_err("failed to intialize sysfs.\n");
+ rv = 1;
+ goto release;
+ }
strcpy(info.text_version, sra->text_version);
info.component_size = s->size*2;
info.new_level = s->level;
strcpy(info.text_version, sra->text_version);
info.component_size = s->size*2;
info.new_level = s->level;
char *c;
struct mdu_array_info_s array;
struct mdinfo info;
char *c;
struct mdu_array_info_s array;
struct mdinfo info;
- sysfs_init(&info, fd, NULL);
+
+ if (sysfs_init(&info, fd, NULL)) {
+ pr_err("failed to intialize sysfs.\n");
+ return 1;
+ }
md_get_array_info(fd, &array);
if (level == 0 &&
md_get_array_info(fd, &array);
if (level == 0 &&
struct mdinfo *d;
if (info2) {
struct mdinfo *d;
if (info2) {
- sysfs_init(info2, fd, st->devnm);
+ if (sysfs_init(info2, fd, st->devnm)) {
+ pr_err("unable to initialize sysfs for %s",
+ st->devnm);
+ free(info2);
+ goto release;
+ }
/* When increasing number of devices, we need to set
* new raid_disks before adding these, or they might
* be rejected.
/* When increasing number of devices, we need to set
* new raid_disks before adding these, or they might
* be rejected.
}
strcpy(last_devnm, mdstat->devnm);
}
strcpy(last_devnm, mdstat->devnm);
- sysfs_init(content, fd, mdstat->devnm);
+ if (sysfs_init(content, fd, mdstat->devnm)) {
+ pr_err("Unable to initialize sysfs for %s\n",
+ mdstat->devnm);
+ rv = 1;
+ break;
+ }
if (mdmon_running(container))
flush_mdmon(container);
if (mdmon_running(container))
flush_mdmon(container);
goto Grow_continue_command_exit;
}
goto Grow_continue_command_exit;
}
- sysfs_init(content, fd2, mdstat->devnm);
+ if (sysfs_init(content, fd2, mdstat->devnm)) {
+ pr_err("Unable to initialize sysfs for %s, Grow cannot continue",
+ mdstat->devnm);
+ ret_val = 1;
+ close(fd2);
+ goto Grow_continue_command_exit;
+ }
if (mdfd < 0)
goto out_unlock;
if (mdfd < 0)
goto out_unlock;
- sysfs_init(&info, mdfd, NULL);
+ if (sysfs_init(&info, mdfd, NULL)) {
+ pr_err("unable to initialize sysfs for %s\n",
+ chosen_name);
+ rv = 2;
+ goto out_unlock;
+ }
if (set_array_info(mdfd, st, &info) != 0) {
pr_err("failed to set array info for %s: %s\n",
if (set_array_info(mdfd, st, &info) != 0) {
pr_err("failed to set array info for %s: %s\n",
pr_err("%s does not appear to be a component of any array\n", devname);
return 1;
}
pr_err("%s does not appear to be a component of any array\n", devname);
return 1;
}
- sysfs_init(&mdi, -1, ent->devnm);
+ if (sysfs_init(&mdi, -1, ent->devnm)) {
+ pr_err("unable to initialize sysfs for: %s\n", devname);
+ return 1;
+ }
mdfd = open_dev_excl(ent->devnm);
if (mdfd > 0) {
close(mdfd);
mdfd = open_dev_excl(ent->devnm);
if (mdfd > 0) {
close(mdfd);
int busy = 0;
int raid_slot = -1;
int busy = 0;
int raid_slot = -1;
+ if (sysfs_init(&info, fd, NULL)) {
+ pr_err("sysfs not availabile for %s\n", devname);
+ goto abort;
+ }
+
if (md_get_array_info(fd, &array)) {
pr_err("Cannot get array info for %s\n", devname);
goto abort;
}
if (md_get_array_info(fd, &array)) {
pr_err("Cannot get array info for %s\n", devname);
goto abort;
}
- sysfs_init(&info, fd, NULL);
-
/* array.size is only 32 bits and may be truncated.
* So read from sysfs if possible, and record number of sectors
*/
/* array.size is only 32 bits and may be truncated.
* So read from sysfs if possible, and record number of sectors
*/
*/
struct mdinfo mdi;
char buf[21];
*/
struct mdinfo mdi;
char buf[21];
- sysfs_init(&mdi, -1, devnm);
+
+ if (sysfs_init(&mdi, -1, devnm))
+ return 2;
if (sysfs_get_str(&mdi, NULL, "sync_action",
buf, 20) > 0 &&
strcmp(buf,"idle\n") != 0) {
if (sysfs_get_str(&mdi, NULL, "sync_action",
buf, 20) > 0 &&
strcmp(buf,"idle\n") != 0) {
- sysfs_init(&sra, mdfd, NULL);
+ if (sysfs_init(&sra, mdfd, NULL)) {
+ rv = 1;
+ break;
+ }
if (array_size == MAX_SIZE)
err = sysfs_set_str(&sra, NULL, "array_size", "default");
else
if (array_size == MAX_SIZE)
err = sysfs_set_str(&sra, NULL, "array_size", "default");
else
{
int fd = open(dev, O_RDONLY);
struct mdinfo mdi;
{
int fd = open(dev, O_RDONLY);
struct mdinfo mdi;
if (fd < 0) {
pr_err("Couldn't open %s: %s\n", dev, strerror(errno));
return 1;
}
if (fd < 0) {
pr_err("Couldn't open %s: %s\n", dev, strerror(errno));
return 1;
}
- sysfs_init(&mdi, fd, NULL);
+ retval = sysfs_init(&mdi, fd, NULL);
- if (!mdi.sys_name[0]) {
pr_err("%s is no an md array\n", dev);
return 1;
}
pr_err("%s is no an md array\n", dev);
return 1;
}
* else use devnm.
*/
extern int sysfs_open(char *devnm, char *devname, char *attr);
* else use devnm.
*/
extern int sysfs_open(char *devnm, char *devname, char *attr);
-extern void sysfs_init(struct mdinfo *mdi, int fd, char *devnm);
+extern int sysfs_init(struct mdinfo *mdi, int fd, char *devnm);
extern void sysfs_init_dev(struct mdinfo *mdi, unsigned long devid);
extern void sysfs_free(struct mdinfo *sra);
extern struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options);
extern void sysfs_init_dev(struct mdinfo *mdi, unsigned long devid);
extern void sysfs_free(struct mdinfo *sra);
extern struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options);
sizeof(mdi->sys_name), "dev-%s", devid2kname(devid));
}
sizeof(mdi->sys_name), "dev-%s", devid2kname(devid));
}
-void sysfs_init(struct mdinfo *mdi, int fd, char *devnm)
+int sysfs_init(struct mdinfo *mdi, int fd, char *devnm)
{
struct stat stb;
char fname[MAX_SYSFS_PATH_LEN];
{
struct stat stb;
char fname[MAX_SYSFS_PATH_LEN];
mdi->sys_name[0] = 0;
if (fd >= 0)
devnm = fd2devnm(fd);
if (devnm == NULL)
mdi->sys_name[0] = 0;
if (fd >= 0)
devnm = fd2devnm(fd);
if (devnm == NULL)
snprintf(fname, MAX_SYSFS_PATH_LEN, "/sys/block/%s/md", devnm);
if (stat(fname, &stb))
snprintf(fname, MAX_SYSFS_PATH_LEN, "/sys/block/%s/md", devnm);
if (stat(fname, &stb))
if (!S_ISDIR(stb.st_mode))
if (!S_ISDIR(stb.st_mode))
strcpy(mdi->sys_name, devnm);
strcpy(mdi->sys_name, devnm);
+
+ retval = 0;
+out:
+ return retval;
}
struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options)
}
struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options)
struct dirent *de;
sra = xcalloc(1, sizeof(*sra));
struct dirent *de;
sra = xcalloc(1, sizeof(*sra));
- sysfs_init(sra, fd, devnm);
- if (sra->sys_name[0] == 0) {
+ if (sysfs_init(sra, fd, devnm)) {
free(sra);
return NULL;
}
free(sra);
return NULL;
}