From: NeilBrown Date: Mon, 9 Jul 2012 07:14:16 +0000 (+1000) Subject: Introduce pr_err for printing error messages. X-Git-Tag: mdadm-3.3-rc1~286 X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fmdadm.git;a=commitdiff_plain;h=e7b84f9d5029338980d99d04b479ce814d4c4fcb Introduce pr_err for printing error messages. 'pr_err("' is a lot shorter than 'fprintf(stderr, Name ": ' cont_err() is also available. Signed-off-by: NeilBrown --- diff --git a/Assemble.c b/Assemble.c index 227d66fc..f06fb5c1 100644 --- a/Assemble.c +++ b/Assemble.c @@ -81,36 +81,34 @@ static int ident_matches(struct mddev_ident *ident, same_uuid(content->uuid, ident->uuid, tst->ss->swapuuid)==0 && memcmp(content->uuid, uuid_zero, sizeof(int[4])) != 0) { if (devname) - fprintf(stderr, Name ": %s has wrong uuid.\n", - devname); + pr_err("%s has wrong uuid.\n", devname); return 0; } if (ident->name[0] && (!update || strcmp(update, "name")!= 0) && name_matches(content->name, ident->name, homehost)==0) { if (devname) - fprintf(stderr, Name ": %s has wrong name.\n", - devname); + pr_err("%s has wrong name.\n", devname); return 0; } if (ident->super_minor != UnSet && ident->super_minor != content->array.md_minor) { if (devname) - fprintf(stderr, Name ": %s has wrong super-minor.\n", - devname); + pr_err("%s has wrong super-minor.\n", + devname); return 0; } if (ident->level != UnSet && ident->level != content->array.level) { if (devname) - fprintf(stderr, Name ": %s has wrong raid level.\n", - devname); + pr_err("%s has wrong raid level.\n", + devname); return 0; } if (ident->raid_disks != UnSet && ident->raid_disks!= content->array.raid_disks) { if (devname) - fprintf(stderr, Name ": %s requires wrong number of drives.\n", - devname); + pr_err("%s requires wrong number of drives.\n", + devname); return 0; } if (ident->member && ident->member[0]) { @@ -118,13 +116,13 @@ static int ident_matches(struct mddev_ident *ident, char *s = strchr(content->text_version+1, '/'); if (s == NULL) { if (devname) - fprintf(stderr, Name ": %s is not a container and one is required.\n", - devname); + pr_err("%s is not a container and one is required.\n", + devname); return 0; } else if (strcmp(ident->member, s+1) != 0) { if (devname) - fprintf(stderr, Name ": skipping wrong member %s is %s\n", - content->text_version, devname); + pr_err("skipping wrong member %s is %s\n", + content->text_version, devname); return 0; } } @@ -253,8 +251,8 @@ int Assemble(struct supertype *st, char *mddev, ident->name[0] == 0 && (ident->container == NULL || ident->member == NULL) && ident->devices == NULL) { - fprintf(stderr, Name ": No identity information available for %s - cannot assemble.\n", - mddev ? mddev : "further assembly"); + pr_err("No identity information available for %s - cannot assemble.\n", + mddev ? mddev : "further assembly"); return 1; } @@ -282,8 +280,8 @@ int Assemble(struct supertype *st, char *mddev, if (!st && ident->st) st = ident->st; if (verbose>0) - fprintf(stderr, Name ": looking for devices for %s\n", - mddev ? mddev : "further assembly"); + pr_err("looking for devices for %s\n", + mddev ? mddev : "further assembly"); /* first walk the list of devices to find a consistent set * that match the criterea, if that is possible. @@ -304,7 +302,7 @@ int Assemble(struct supertype *st, char *mddev, if (ident->devices && !match_oneof(ident->devices, devname)) { if (report_missmatch) - fprintf(stderr, Name ": %s is not one of %s\n", devname, ident->devices); + pr_err("%s is not one of %s\n", devname, ident->devices); continue; } @@ -313,17 +311,17 @@ int Assemble(struct supertype *st, char *mddev, dfd = dev_open(devname, O_RDONLY); if (dfd < 0) { if (report_missmatch) - fprintf(stderr, Name ": cannot open device %s: %s\n", - devname, strerror(errno)); + pr_err("cannot open device %s: %s\n", + devname, strerror(errno)); tmpdev->used = 2; } else if (fstat(dfd, &stb)< 0) { /* Impossible! */ - fprintf(stderr, Name ": fstat failed for %s: %s\n", - devname, strerror(errno)); + pr_err("fstat failed for %s: %s\n", + devname, strerror(errno)); tmpdev->used = 2; } else if ((stb.st_mode & S_IFMT) != S_IFBLK) { - fprintf(stderr, Name ": %s is not a block device.\n", - devname); + pr_err("%s is not a block device.\n", + devname); tmpdev->used = 2; } else if (must_be_container(dfd)) { if (st) { @@ -331,55 +329,55 @@ int Assemble(struct supertype *st, char *mddev, * be another one. */ if (report_missmatch) - fprintf(stderr, Name ": %s is a container, but we are looking for components\n", - devname); + pr_err("%s is a container, but we are looking for components\n", + devname); tmpdev->used = 2; #if !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO) } if (!tst && (tst = super_by_fd(dfd, NULL)) == NULL) { if (report_missmatch) - fprintf(stderr, Name ": not a recognisable container: %s\n", - devname); + pr_err("not a recognisable container: %s\n", + devname); tmpdev->used = 2; #endif } else if (!tst->ss->load_container || tst->ss->load_container(tst, dfd, NULL)) { if (report_missmatch) - fprintf(stderr, Name ": no correct container type: %s\n", - devname); + pr_err("no correct container type: %s\n", + devname); tmpdev->used = 2; } else if (auto_assem && !conf_test_metadata(tst->ss->name, (pol = devnum_policy(stb.st_rdev)), tst->ss->match_home(tst, homehost) == 1)) { if (report_missmatch) - fprintf(stderr, Name ": %s has metadata type %s for which " - "auto-assembly is disabled\n", - devname, tst->ss->name); + pr_err("%s has metadata type %s for which " + "auto-assembly is disabled\n", + devname, tst->ss->name); tmpdev->used = 2; } else found_container = 1; } else { if (!tst && (tst = guess_super(dfd)) == NULL) { if (report_missmatch) - fprintf(stderr, Name ": no recogniseable superblock on %s\n", - devname); + pr_err("no recogniseable superblock on %s\n", + devname); tmpdev->used = 2; } else if (tst->ss->load_super(tst,dfd, NULL)) { if (report_missmatch) - fprintf(stderr, Name ": no RAID superblock on %s\n", - devname); + pr_err("no RAID superblock on %s\n", + devname); tmpdev->used = 2; } else if (tst->ss->compare_super == NULL) { if (report_missmatch) - fprintf(stderr, Name ": Cannot assemble %s metadata on %s\n", - tst->ss->name, devname); + pr_err("Cannot assemble %s metadata on %s\n", + tst->ss->name, devname); tmpdev->used = 2; } else if (auto_assem && st == NULL && !conf_test_metadata(tst->ss->name, (pol = devnum_policy(stb.st_rdev)), tst->ss->match_home(tst, homehost) == 1)) { if (report_missmatch) - fprintf(stderr, Name ": %s has metadata type %s for which " - "auto-assembly is disabled\n", - devname, tst->ss->name); + pr_err("%s has metadata type %s for which " + "auto-assembly is disabled\n", + devname, tst->ss->name); tmpdev->used = 2; } } @@ -395,7 +393,7 @@ int Assemble(struct supertype *st, char *mddev, goto loop; - fprintf(stderr, Name ": %s has no superblock - assembly aborted\n", + pr_err("%s has no superblock - assembly aborted\n", devname); if (st) st->ss->free_super(st); @@ -415,7 +413,7 @@ int Assemble(struct supertype *st, char *mddev, dfd = dev_open(devname, O_RDONLY | O_EXCL); if (dfd < 0) { if (report_missmatch) - fprintf(stderr, Name ": %s is busy - skipping\n", devname); + pr_err("%s is busy - skipping\n", devname); goto loop; } close(dfd); @@ -424,7 +422,7 @@ int Assemble(struct supertype *st, char *mddev, if (ident->container[0] == '/' && !same_dev(ident->container, devname)) { if (report_missmatch) - fprintf(stderr, Name ": %s is not the container required (%s)\n", + pr_err("%s is not the container required (%s)\n", devname, ident->container); goto loop; } @@ -438,7 +436,7 @@ int Assemble(struct supertype *st, char *mddev, if (!parse_uuid(ident->container, uuid) || !same_uuid(content->uuid, uuid, tst->ss->swapuuid)) { if (report_missmatch) - fprintf(stderr, Name ": %s has wrong UUID to be required container\n", + pr_err("%s has wrong UUID to be required container\n", devname); goto loop; } @@ -447,7 +445,7 @@ int Assemble(struct supertype *st, char *mddev, /* It is worth looking inside this container. */ if (verbose > 0) - fprintf(stderr, Name ": looking in container %s\n", + pr_err("looking in container %s\n", devname); for (content = tst->ss->container_content(tst, NULL); @@ -460,12 +458,12 @@ int Assemble(struct supertype *st, char *mddev, /* message already printed */; else if (is_member_busy(content->text_version)) { if (report_missmatch) - fprintf(stderr, Name ": member %s in %s is already assembled\n", + pr_err("member %s in %s is already assembled\n", content->text_version, devname); } else if (content->array.state & (1<text_version, devname); } else @@ -478,7 +476,7 @@ int Assemble(struct supertype *st, char *mddev, st = tst; tst = NULL; if (!auto_assem && inargv && tmpdev->next != NULL) { - fprintf(stderr, Name ": %s is a container, but is not " + pr_err("%s is a container, but is not " "only device given: confused and aborting\n", devname); st->ss->free_super(st); @@ -487,7 +485,7 @@ int Assemble(struct supertype *st, char *mddev, return 1; } if (verbose > 0) - fprintf(stderr, Name ": found match on member %s in %s\n", + pr_err("found match on member %s in %s\n", content->text_version, devname); /* make sure we finished the loop */ @@ -510,7 +508,7 @@ int Assemble(struct supertype *st, char *mddev, dfd = dev_open(devname, O_RDONLY | O_EXCL); if (dfd < 0) { if (report_missmatch) - fprintf(stderr, Name ": %s is busy - skipping\n", devname); + pr_err("%s is busy - skipping\n", devname); goto loop; } close(dfd); @@ -549,13 +547,13 @@ int Assemble(struct supertype *st, char *mddev, /* We can do something */ if (first) {/* just ignore this one */ if (report_missmatch) - fprintf(stderr, Name ": %s misses out due to wrong homehost\n", + pr_err("%s misses out due to wrong homehost\n", devname); goto loop; } else { /* reject all those sofar */ struct mddev_dev *td; if (report_missmatch) - fprintf(stderr, Name ": %s overrides previous devices due to good homehost\n", + pr_err("%s overrides previous devices due to good homehost\n", devname); for (td=devlist; td != tmpdev; td=td->next) if (td->used == 1) @@ -565,7 +563,7 @@ int Assemble(struct supertype *st, char *mddev, } } } - fprintf(stderr, Name ": superblock on %s doesn't match others - assembly aborted\n", + pr_err("superblock on %s doesn't match others - assembly aborted\n", devname); tst->ss->free_super(tst); st->ss->free_super(st); @@ -616,7 +614,7 @@ int Assemble(struct supertype *st, char *mddev, if (tmpdev->used != 3) continue; if (stat(tmpdev->devname, &stb)< 0) { - fprintf(stderr, Name ": fstat failed for %s: %s\n", + pr_err("fstat failed for %s: %s\n", tmpdev->devname, strerror(errno)); tmpdev->used = 2; } else { @@ -692,20 +690,20 @@ int Assemble(struct supertype *st, char *mddev, mddev = chosen_name; vers = md_get_version(mdfd); if (vers < 9000) { - fprintf(stderr, Name ": Assemble requires driver version 0.90.0 or later.\n" + pr_err("Assemble requires driver version 0.90.0 or later.\n" " Upgrade your kernel or try --build\n"); close(mdfd); return 1; } if (mddev_busy(fd2devnum(mdfd))) { - fprintf(stderr, Name ": %s already active, cannot restart it!\n", + pr_err("%s already active, cannot restart it!\n", mddev); for (tmpdev = devlist ; tmpdev && tmpdev->used != 1; tmpdev = tmpdev->next) ; if (tmpdev && auto_assem) - fprintf(stderr, Name ": %s needed for %s...\n", + pr_err("%s needed for %s...\n", mddev, tmpdev->devname); close(mdfd); mdfd = -3; @@ -760,7 +758,7 @@ int Assemble(struct supertype *st, char *mddev, tst = dup_super(st); if (dfd < 0 || tst->ss->load_super(tst, dfd, NULL) != 0) { - fprintf(stderr, Name ": cannot re-read metadata from %s - aborting\n", + pr_err("cannot re-read metadata from %s - aborting\n", devname); if (dfd >= 0) close(dfd); @@ -783,10 +781,9 @@ int Assemble(struct supertype *st, char *mddev, ident->uuid_set, homehost); if (err < 0) { - fprintf(stderr, - Name ": --update=%s not understood" - " for %s metadata\n", - update, tst->ss->name); + pr_err("--update=%s not understood" + " for %s metadata\n", + update, tst->ss->name); tst->ss->free_super(tst); free(tst); close(mdfd); @@ -801,7 +798,7 @@ int Assemble(struct supertype *st, char *mddev, memcpy(ident->uuid, content->uuid, 16); } if (tst->ss->store_super(tst, dfd)) - fprintf(stderr, Name ": Could not re-write superblock on %s.\n", + pr_err("Could not re-write superblock on %s.\n", devname); close(dfd); @@ -810,7 +807,7 @@ int Assemble(struct supertype *st, char *mddev, if (bitmap_update_uuid(ident->bitmap_fd, content->uuid, tst->ss->swapuuid) != 0) - fprintf(stderr, Name ": Could not update uuid on external bitmap.\n"); + pr_err("Could not update uuid on external bitmap.\n"); else bitmap_done = 1; } @@ -823,7 +820,7 @@ int Assemble(struct supertype *st, char *mddev, dfd = dev_open(devname, O_RDWR|O_EXCL); if (dfd < 0 || tst->ss->load_super(tst, dfd, NULL) != 0) { - fprintf(stderr, Name ": cannot re-read metadata from %s - aborting\n", + pr_err("cannot re-read metadata from %s - aborting\n", devname); if (dfd >= 0) close(dfd); @@ -840,7 +837,7 @@ int Assemble(struct supertype *st, char *mddev, stat(devname, &stb); if (verbose > 0) - fprintf(stderr, Name ": %s is identified as a member of %s, slot %d.\n", + pr_err("%s is identified as a member of %s, slot %d.\n", devname, mddev, content->disk.raid_disk); devices[devcnt].devname = devname; devices[devcnt].uptodate = 0; @@ -891,7 +888,7 @@ int Assemble(struct supertype *st, char *mddev, * Could be a mis-detection caused by overlapping * partitions. fail-safe. */ - fprintf(stderr, Name ": WARNING %s and %s appear" + pr_err("WARNING %s and %s appear" " to have very similar superblocks.\n" " If they are really different, " "please --zero the superblock on one\n" @@ -915,7 +912,7 @@ int Assemble(struct supertype *st, char *mddev, } if (devcnt == 0) { - fprintf(stderr, Name ": no devices found for %s\n", + pr_err("no devices found for %s\n", mddev); if (st) st->ss->free_super(st); @@ -965,7 +962,7 @@ int Assemble(struct supertype *st, char *mddev, devices[most_recent].i.disk.raid_disk >= 0 && devmap[j * content->array.raid_disks + devices[most_recent].i.disk.raid_disk] == 0) { if (verbose > -1) - fprintf(stderr, Name ": ignoring %s as it reports %s as failed\n", + pr_err("ignoring %s as it reports %s as failed\n", devices[j].devname, devices[most_recent].devname); best[i] = -1; continue; @@ -1022,14 +1019,14 @@ int Assemble(struct supertype *st, char *mddev, current_events = devices[chosen_drive].i.events; add_another: if (verbose >= 0) - fprintf(stderr, Name ": forcing event count in %s(%d) from %d upto %d\n", + pr_err("forcing event count in %s(%d) from %d upto %d\n", devices[chosen_drive].devname, devices[chosen_drive].i.disk.raid_disk, (int)(devices[chosen_drive].i.events), (int)(devices[most_recent].i.events)); fd = dev_open(devices[chosen_drive].devname, O_RDWR|O_EXCL); if (fd < 0) { - fprintf(stderr, Name ": Couldn't open %s for write - not updating\n", + pr_err("Couldn't open %s for write - not updating\n", devices[chosen_drive].devname); devices[chosen_drive].i.events = 0; continue; @@ -1037,7 +1034,7 @@ int Assemble(struct supertype *st, char *mddev, tst = dup_super(st); if (tst->ss->load_super(tst,fd, NULL)) { close(fd); - fprintf(stderr, Name ": RAID superblock disappeared from %s - not updating.\n", + pr_err("RAID superblock disappeared from %s - not updating.\n", devices[chosen_drive].devname); devices[chosen_drive].i.events = 0; continue; @@ -1049,7 +1046,7 @@ int Assemble(struct supertype *st, char *mddev, if (tst->ss->store_super(tst, fd)) { close(fd); - fprintf(stderr, Name ": Could not re-write superblock on %s\n", + pr_err("Could not re-write superblock on %s\n", devices[chosen_drive].devname); devices[chosen_drive].i.events = 0; tst->ss->free_super(tst); @@ -1097,7 +1094,7 @@ int Assemble(struct supertype *st, char *mddev, continue; chosen_drive = j; if ((fd=dev_open(devices[j].devname, O_RDONLY|O_EXCL))< 0) { - fprintf(stderr, Name ": Cannot open %s: %s\n", + pr_err("Cannot open %s: %s\n", devices[j].devname, strerror(errno)); close(mdfd); free(devices); @@ -1105,7 +1102,7 @@ int Assemble(struct supertype *st, char *mddev, } if (st->ss->load_super(st,fd, NULL)) { close(fd); - fprintf(stderr, Name ": RAID superblock has disappeared from %s\n", + pr_err("RAID superblock has disappeared from %s\n", devices[j].devname); close(mdfd); free(devices); @@ -1114,7 +1111,7 @@ int Assemble(struct supertype *st, char *mddev, close(fd); } if (st->sb == NULL) { - fprintf(stderr, Name ": No suitable drives found for %s\n", mddev); + pr_err("No suitable drives found for %s\n", mddev); close(mdfd); free(devices); return 1; @@ -1145,20 +1142,18 @@ int Assemble(struct supertype *st, char *mddev, verbose, 0, NULL)) { if (force) { if (verbose >= 0) - fprintf(stderr, Name ": " - "clearing FAULTY flag for device %d in %s for %s\n", + pr_err("clearing FAULTY flag for device %d in %s for %s\n", j, mddev, devices[j].devname); change = 1; } else { if (verbose >= -1) - fprintf(stderr, Name ": " - "device %d in %s has wrong state in superblock, but %s seems ok\n", + pr_err("device %d in %s has wrong state in superblock, but %s seems ok\n", i, mddev, devices[j].devname); } } #if 0 if (!(super.disks[i].i.disk.state & (1 << MD_DISK_FAULTY))) { - fprintf(stderr, Name ": devices %d of %s is not marked FAULTY in superblock, but cannot be found\n", + pr_err("devices %d of %s is not marked FAULTY in superblock, but cannot be found\n", i, mddev); } #endif @@ -1177,7 +1172,7 @@ int Assemble(struct supertype *st, char *mddev, int fd; fd = dev_open(devices[chosen_drive].devname, O_RDWR|O_EXCL); if (fd < 0) { - fprintf(stderr, Name ": Could not open %s for write - cannot Assemble array.\n", + pr_err("Could not open %s for write - cannot Assemble array.\n", devices[chosen_drive].devname); close(mdfd); free(devices); @@ -1185,14 +1180,14 @@ int Assemble(struct supertype *st, char *mddev, } if (st->ss->store_super(st, fd)) { close(fd); - fprintf(stderr, Name ": Could not re-write superblock on %s\n", + pr_err("Could not re-write superblock on %s\n", devices[chosen_drive].devname); close(mdfd); free(devices); return 1; } if (verbose >= 0) - fprintf(stderr, Name ": Marking array %s as 'clean'\n", + pr_err("Marking array %s as 'clean'\n", mddev); close(fd); } @@ -1206,7 +1201,7 @@ int Assemble(struct supertype *st, char *mddev, int err = 0; int *fdlist = malloc(sizeof(int)* bestcnt); if (verbose > 0) - fprintf(stderr, Name ":%s has an active reshape - checking " + pr_err(":%s has an active reshape - checking " "if critical section needs to be restored\n", chosen_name); for (i=0; i= 0) { fdlist[i] = dev_open(devices[j].devname, O_RDWR|O_EXCL); if (fdlist[i] < 0) { - fprintf(stderr, Name ": Could not open %s for write - cannot Assemble array.\n", + pr_err("Could not open %s for write - cannot Assemble array.\n", devices[j].devname); err = 1; break; @@ -1230,7 +1225,7 @@ int Assemble(struct supertype *st, char *mddev, backup_file, verbose > 0); if (err && invalid_backup) { if (verbose > 0) - fprintf(stderr, Name ": continuing" + pr_err("continuing" " without restoring backup\n"); err = 0; } @@ -1240,9 +1235,9 @@ int Assemble(struct supertype *st, char *mddev, if (fdlist[i]>=0) close(fdlist[i]); } if (err) { - fprintf(stderr, Name ": Failed to restore critical section for reshape, sorry.\n"); + pr_err("Failed to restore critical section for reshape, sorry.\n"); if (backup_file == NULL) - fprintf(stderr," Possibly you needed to specify the --backup-file\n"); + cont_err("Possibly you needed to specify the --backup-file\n"); close(mdfd); free(devices); return err; @@ -1266,7 +1261,7 @@ int Assemble(struct supertype *st, char *mddev, rv = set_array_info(mdfd, st, content); if (rv) { - fprintf(stderr, Name ": failed to set array info for %s: %s\n", + pr_err("failed to set array info for %s: %s\n", mddev, strerror(errno)); ioctl(mdfd, STOP_ARRAY, NULL); close(mdfd); @@ -1275,7 +1270,7 @@ int Assemble(struct supertype *st, char *mddev, } if (ident->bitmap_fd >= 0) { if (ioctl(mdfd, SET_BITMAP_FILE, ident->bitmap_fd) != 0) { - fprintf(stderr, Name ": SET_BITMAP_FILE failed.\n"); + pr_err("SET_BITMAP_FILE failed.\n"); ioctl(mdfd, STOP_ARRAY, NULL); close(mdfd); free(devices); @@ -1285,7 +1280,7 @@ int Assemble(struct supertype *st, char *mddev, /* From config file */ int bmfd = open(ident->bitmap_file, O_RDWR); if (bmfd < 0) { - fprintf(stderr, Name ": Could not open bitmap file %s\n", + pr_err("Could not open bitmap file %s\n", ident->bitmap_file); ioctl(mdfd, STOP_ARRAY, NULL); close(mdfd); @@ -1293,7 +1288,7 @@ int Assemble(struct supertype *st, char *mddev, return 1; } if (ioctl(mdfd, SET_BITMAP_FILE, bmfd) != 0) { - fprintf(stderr, Name ": Failed to set bitmapfile for %s\n", mddev); + pr_err("Failed to set bitmapfile for %s\n", mddev); close(bmfd); ioctl(mdfd, STOP_ARRAY, NULL); close(mdfd); @@ -1323,32 +1318,31 @@ int Assemble(struct supertype *st, char *mddev, rv = add_disk(mdfd, st, content, &devices[j].i); if (rv) { - fprintf(stderr, Name ": failed to add " - "%s to %s: %s\n", - devices[j].devname, - mddev, - strerror(errno)); + pr_err("failed to add " + "%s to %s: %s\n", + devices[j].devname, + mddev, + strerror(errno)); if (i < content->array.raid_disks || i == bestcnt) okcnt--; else sparecnt--; } else if (verbose > 0) - fprintf(stderr, Name ": added %s " - "to %s as %d%s\n", - devices[j].devname, mddev, - devices[j].i.disk.raid_disk, - devices[j].uptodate?"": - " (possibly out of date)"); + pr_err("added %s to %s as %d%s\n", + devices[j].devname, mddev, + devices[j].i.disk.raid_disk, + devices[j].uptodate?"": + " (possibly out of date)"); } else if (verbose > 0 && i < content->array.raid_disks) - fprintf(stderr, Name ": no uptodate device for " + pr_err("no uptodate device for " "slot %d of %s\n", i, mddev); } if (content->array.level == LEVEL_CONTAINER) { if (verbose >= 0) { - fprintf(stderr, Name ": Container %s has been " + pr_err("Container %s has been " "assembled with %d drive%s", mddev, okcnt+sparecnt, okcnt+sparecnt==1?"":"s"); if (okcnt < (unsigned)content->array.raid_disks) @@ -1390,7 +1384,7 @@ int Assemble(struct supertype *st, char *mddev, rv = ioctl(mdfd, RUN_ARRAY, NULL); if (rv == 0) { if (verbose >= 0) { - fprintf(stderr, Name ": %s has been started with %d drive%s", + pr_err("%s has been started with %d drive%s", mddev, okcnt, okcnt==1?"":"s"); if (okcnt < (unsigned)content->array.raid_disks) fprintf(stderr, " (out of %d)", content->array.raid_disks); @@ -1432,9 +1426,8 @@ int Assemble(struct supertype *st, char *mddev, rv = add_disk(mdfd, st, content, &devices[j].i); if (rv == 0 && verbose >= 0) - fprintf(stderr, - Name ": %s has been re-added.\n", - devices[j].devname); + pr_err("%s has been re-added.\n", + devices[j].devname); } } } @@ -1469,18 +1462,18 @@ int Assemble(struct supertype *st, char *mddev, free(devices); return 0; } - fprintf(stderr, Name ": failed to RUN_ARRAY %s: %s\n", + pr_err("failed to RUN_ARRAY %s: %s\n", mddev, strerror(errno)); if (!enough(content->array.level, content->array.raid_disks, content->array.layout, 1, avail)) - fprintf(stderr, Name ": Not enough devices to " + pr_err("Not enough devices to " "start the array.\n"); else if (!enough(content->array.level, content->array.raid_disks, content->array.layout, clean, avail)) - fprintf(stderr, Name ": Not enough devices to " + pr_err("Not enough devices to " "start the array while not clean " "- consider --force.\n"); @@ -1491,8 +1484,8 @@ int Assemble(struct supertype *st, char *mddev, return 1; } if (runstop == -1) { - fprintf(stderr, Name ": %s assembled from %d drive%s", - mddev, okcnt, okcnt==1?"":"s"); + pr_err("%s assembled from %d drive%s", + mddev, okcnt, okcnt==1?"":"s"); if (okcnt != (unsigned)content->array.raid_disks) fprintf(stderr, " (out of %d)", content->array.raid_disks); fprintf(stderr, ", but not started.\n"); @@ -1501,7 +1494,7 @@ int Assemble(struct supertype *st, char *mddev, return 0; } if (verbose >= -1) { - fprintf(stderr, Name ": %s assembled from %d drive%s", mddev, okcnt, okcnt==1?"":"s"); + pr_err("%s assembled from %d drive%s", mddev, okcnt, okcnt==1?"":"s"); if (rebuilding_cnt) fprintf(stderr, "%s %d rebuilding", sparecnt?", ":" and ", rebuilding_cnt); if (sparecnt) @@ -1538,7 +1531,7 @@ int Assemble(struct supertype *st, char *mddev, dev = makedev(devices[chosen_drive].i.disk.major, devices[chosen_drive].i.disk.minor); if (ioctl(mdfd, START_ARRAY, dev)) { - fprintf(stderr, Name ": Cannot start array: %s\n", + pr_err("Cannot start array: %s\n", strerror(errno)); } @@ -1662,15 +1655,13 @@ int assemble_container_content(struct supertype *st, int mdfd, if (verbose >= 0) { if (err) - fprintf(stderr, Name - ": array %s now has %d device%s", - chosen_name, working + preexist, - working + preexist == 1 ? "":"s"); + pr_err("array %s now has %d device%s", + chosen_name, working + preexist, + working + preexist == 1 ? "":"s"); else - fprintf(stderr, Name - ": Started %s with %d device%s", - chosen_name, working + preexist, - working + preexist == 1 ? "":"s"); + pr_err("Started %s with %d device%s", + chosen_name, working + preexist, + working + preexist == 1 ? "":"s"); if (preexist) fprintf(stderr, " (%d new)", working); if (expansion) @@ -1684,10 +1675,9 @@ int assemble_container_content(struct supertype *st, int mdfd, /* FIXME should have an O_EXCL and wait for read-auto */ } else { if (verbose >= 0) { - fprintf(stderr, Name - ": %s assembled with %d device%s", - chosen_name, preexist + working, - preexist + working == 1 ? "":"s"); + pr_err("%s assembled with %d device%s", + chosen_name, preexist + working, + preexist + working == 1 ? "":"s"); if (preexist) fprintf(stderr, " (%d new)", working); fprintf(stderr, " but not started\n"); diff --git a/Build.c b/Build.c index 4338e190..8e0307db 100644 --- a/Build.c +++ b/Build.c @@ -66,19 +66,19 @@ int Build(char *mddev, int chunk, int level, int layout, continue; } if (stat(dv->devname, &stb)) { - fprintf(stderr, Name ": Cannot find %s: %s\n", + pr_err("Cannot find %s: %s\n", dv->devname, strerror(errno)); return 1; } if ((stb.st_mode & S_IFMT) != S_IFBLK) { - fprintf(stderr, Name ": %s is not a block device.\n", + pr_err("%s is not a block device.\n", dv->devname); return 1; } } if (raiddisks != subdevs) { - fprintf(stderr, Name ": requested %d devices in array but listed %d\n", + pr_err("requested %d devices in array but listed %d\n", raiddisks, subdevs); return 1; } @@ -91,22 +91,19 @@ int Build(char *mddev, int chunk, int level, int layout, case 10: layout = 0x102; /* near=2, far=1 */ if (verbose > 0) - fprintf(stderr, - Name ": layout defaults to n1\n"); + pr_err("layout defaults to n1\n"); break; case 5: case 6: layout = map_name(r5layout, "default"); if (verbose > 0) - fprintf(stderr, - Name ": layout defaults to %s\n", map_num(r5layout, layout)); + pr_err("layout defaults to %s\n", map_num(r5layout, layout)); break; case LEVEL_FAULTY: layout = map_name(faultylayout, "default"); if (verbose > 0) - fprintf(stderr, - Name ": layout defaults to %s\n", map_num(faultylayout, layout)); + pr_err("layout defaults to %s\n", map_num(faultylayout, layout)); break; } @@ -148,17 +145,17 @@ int Build(char *mddev, int chunk, int level, int layout, array.chunk_size = chunk*1024; array.layout = layout; if (ioctl(mdfd, SET_ARRAY_INFO, &array)) { - fprintf(stderr, Name ": SET_ARRAY_INFO failed for %s: %s\n", + pr_err("SET_ARRAY_INFO failed for %s: %s\n", mddev, strerror(errno)); goto abort; } } else if (bitmap_file) { - fprintf(stderr, Name ": bitmaps not supported with this kernel\n"); + pr_err("bitmaps not supported with this kernel\n"); goto abort; } if (bitmap_file && level <= 0) { - fprintf(stderr, Name ": bitmaps not meaningful with level %s\n", + pr_err("bitmaps not meaningful with level %s\n", map_num(pers, level)?:"given"); goto abort; } @@ -169,18 +166,18 @@ int Build(char *mddev, int chunk, int level, int layout, if (strcmp("missing", dv->devname) == 0) continue; if (stat(dv->devname, &stb)) { - fprintf(stderr, Name ": Weird: %s has disappeared.\n", + pr_err("Weird: %s has disappeared.\n", dv->devname); goto abort; } if ((stb.st_mode & S_IFMT)!= S_IFBLK) { - fprintf(stderr, Name ": Wierd: %s is no longer a block device.\n", + pr_err("Wierd: %s is no longer a block device.\n", dv->devname); goto abort; } fd = open(dv->devname, O_RDONLY|O_EXCL); if (fd < 0) { - fprintf(stderr, Name ": Cannot open %s: %s\n", + pr_err("Cannot open %s: %s\n", dv->devname, strerror(errno)); goto abort; } @@ -198,13 +195,13 @@ int Build(char *mddev, int chunk, int level, int layout, disk.major = major(stb.st_rdev); disk.minor = minor(stb.st_rdev); if (ioctl(mdfd, ADD_NEW_DISK, &disk)) { - fprintf(stderr, Name ": ADD_NEW_DISK failed for %s: %s\n", + pr_err("ADD_NEW_DISK failed for %s: %s\n", dv->devname, strerror(errno)); goto abort; } } else { if (ioctl(mdfd, REGISTER_DEV, &stb.st_rdev)) { - fprintf(stderr, Name ": REGISTER_DEV failed for %s: %s.\n", + pr_err("REGISTER_DEV failed for %s: %s.\n", dv->devname, strerror(errno)); goto abort; } @@ -219,7 +216,7 @@ int Build(char *mddev, int chunk, int level, int layout, int major = BITMAP_MAJOR_HI; #if 0 if (bitmap_chunk == UnSet) { - fprintf(stderr, Name ": %s cannot be openned.", + pr_err("%s cannot be openned.", bitmap_file); goto abort; } @@ -227,7 +224,7 @@ int Build(char *mddev, int chunk, int level, int layout, if (vers < 9003) { major = BITMAP_MAJOR_HOSTENDIAN; #ifdef __BIG_ENDIAN - fprintf(stderr, Name ": Warning - bitmaps created on this kernel are not portable\n" + pr_err("Warning - bitmaps created on this kernel are not portable\n" " between different architectures. Consider upgrading the Linux kernel.\n"); #endif } @@ -238,25 +235,25 @@ int Build(char *mddev, int chunk, int level, int layout, } bitmap_fd = open(bitmap_file, O_RDWR); if (bitmap_fd < 0) { - fprintf(stderr, Name ": %s cannot be openned.", + pr_err("%s cannot be openned.", bitmap_file); goto abort; } } if (bitmap_fd >= 0) { if (ioctl(mdfd, SET_BITMAP_FILE, bitmap_fd) < 0) { - fprintf(stderr, Name ": Cannot set bitmap file for %s: %s\n", + pr_err("Cannot set bitmap file for %s: %s\n", mddev, strerror(errno)); goto abort; } } } if (ioctl(mdfd, RUN_ARRAY, ¶m)) { - fprintf(stderr, Name ": RUN_ARRAY failed: %s\n", + pr_err("RUN_ARRAY failed: %s\n", strerror(errno)); if (chunk & (chunk-1)) { - fprintf(stderr, " : Problem may be that chunk size" - " is not a power of 2\n"); + cont_err("Problem may be that chunk size" + " is not a power of 2\n"); } goto abort; } @@ -271,13 +268,13 @@ int Build(char *mddev, int chunk, int level, int layout, chunk |= 0x20000; else chunk |= 0x10000; if (ioctl(mdfd, START_MD, arg)) { - fprintf(stderr, Name ": START_MD failed: %s\n", + pr_err("START_MD failed: %s\n", strerror(errno)); goto abort; } } if (verbose >= 0) - fprintf(stderr, Name ": array %s built and started.\n", + pr_err("array %s built and started.\n", mddev); wait_for(mddev, mdfd); close(mdfd); diff --git a/Create.c b/Create.c index 58d10687..f150954b 100644 --- a/Create.c +++ b/Create.c @@ -42,22 +42,19 @@ static int default_layout(struct supertype *st, int level, int verbose) case 10: layout = 0x102; /* near=2, far=1 */ if (verbose > 0) - fprintf(stderr, - Name ": layout defaults to n2\n"); + pr_err("layout defaults to n2\n"); break; case 5: case 6: layout = map_name(r5layout, "default"); if (verbose > 0) - fprintf(stderr, - Name ": layout defaults to %s\n", map_num(r5layout, layout)); + pr_err("layout defaults to %s\n", map_num(r5layout, layout)); break; case LEVEL_FAULTY: layout = map_name(faultylayout, "default"); if (verbose > 0) - fprintf(stderr, - Name ": layout defaults to %s\n", map_num(faultylayout, layout)); + pr_err("layout defaults to %s\n", map_num(faultylayout, layout)); break; } @@ -126,28 +123,23 @@ int Create(struct supertype *st, char *mddev, if (level == UnSet && st && st->ss->default_geometry) st->ss->default_geometry(st, &level, NULL, NULL); if (level == UnSet) { - fprintf(stderr, - Name ": a RAID level is needed to create an array.\n"); + pr_err("a RAID level is needed to create an array.\n"); return 1; } if (raiddisks < 4 && level == 6) { - fprintf(stderr, - Name ": at least 4 raid-devices needed for level 6\n"); + pr_err("at least 4 raid-devices needed for level 6\n"); return 1; } if (raiddisks > 256 && level == 6) { - fprintf(stderr, - Name ": no more than 256 raid-devices supported for level 6\n"); + pr_err("no more than 256 raid-devices supported for level 6\n"); return 1; } if (raiddisks < 2 && level >= 4) { - fprintf(stderr, - Name ": at least 2 raid-devices needed for level 4 or 5\n"); + pr_err("at least 2 raid-devices needed for level 4 or 5\n"); return 1; } if (level <= 0 && sparedisks) { - fprintf(stderr, - Name ": This level does not support spare devices\n"); + pr_err("This level does not support spare devices\n"); return 1; } @@ -189,21 +181,20 @@ int Create(struct supertype *st, char *mddev, close(fd); } if (st && st->ss->external && sparedisks) { - fprintf(stderr, - Name ": This metadata type does not support " - "spare disks at create time\n"); + pr_err("This metadata type does not support " + "spare disks at create time\n"); return 1; } if (subdevs > raiddisks+sparedisks) { - fprintf(stderr, Name ": You have listed more devices (%d) than are in the array(%d)!\n", subdevs, raiddisks+sparedisks); + pr_err("You have listed more devices (%d) than are in the array(%d)!\n", subdevs, raiddisks+sparedisks); return 1; } if (!have_container && subdevs < raiddisks+sparedisks) { - fprintf(stderr, Name ": You haven't given enough devices (real or missing) to create this array\n"); + pr_err("You haven't given enough devices (real or missing) to create this array\n"); return 1; } if (bitmap_file && level <= 0) { - fprintf(stderr, Name ": bitmaps not meaningful with level %s\n", + pr_err("bitmaps not meaningful with level %s\n", map_num(pers, level)?:"given"); return 1; } @@ -219,7 +210,7 @@ int Create(struct supertype *st, char *mddev, if (level == 10) /* check layout fits in array*/ if ((layout&255) * ((layout>>8)&255) > raiddisks) { - fprintf(stderr, Name ": that layout requires at least %d devices\n", + pr_err("that layout requires at least %d devices\n", (layout&255) * ((layout>>8)&255)); return 1; } @@ -241,7 +232,7 @@ int Create(struct supertype *st, char *mddev, if (get_linux_version() < 2006016 && chunk == 0) { chunk = 64; if (verbose > 0) - fprintf(stderr, Name ": chunk size defaults to 64K\n"); + pr_err("chunk size defaults to 64K\n"); } break; case 1: @@ -251,11 +242,11 @@ int Create(struct supertype *st, char *mddev, if (chunk) { chunk = 0; if (verbose > 0) - fprintf(stderr, Name ": chunk size ignored for this level\n"); + pr_err("chunk size ignored for this level\n"); } break; default: - fprintf(stderr, Name ": unknown level %d\n", level); + pr_err("unknown level %d\n", level); return 1; } @@ -271,7 +262,7 @@ int Create(struct supertype *st, char *mddev, if (do_default_chunk) { /* default chunk was just set */ if (verbose > 0) - fprintf(stderr, Name ": chunk size " + pr_err("chunk size " "defaults to %dK\n", chunk); size &= ~(unsigned long long)(chunk - 1); do_default_chunk = 0; @@ -288,7 +279,7 @@ int Create(struct supertype *st, char *mddev, size &= ~(64ULL-1); if (size && verbose > 0) - fprintf(stderr, Name ": setting size to %lluK\n", + pr_err("setting size to %lluK\n", (unsigned long long)size); } @@ -311,14 +302,14 @@ int Create(struct supertype *st, char *mddev, } dfd = open(dname, O_RDONLY); if (dfd < 0) { - fprintf(stderr, Name ": cannot open %s: %s\n", + pr_err("cannot open %s: %s\n", dname, strerror(errno)); exit(2); } if (fstat(dfd, &stb) != 0 || (stb.st_mode & S_IFMT) != S_IFBLK) { close(dfd); - fprintf(stderr, Name ": %s is not a block device\n", + pr_err("%s is not a block device\n", dname); exit(2); } @@ -364,11 +355,11 @@ int Create(struct supertype *st, char *mddev, if (!st) { int dfd = open(dname, O_RDONLY|O_EXCL); if (dfd < 0) { - fprintf(stderr, Name ": cannot open %s: %s\n", + pr_err("cannot open %s: %s\n", dname, strerror(errno)); exit(2); } - fprintf(stderr, Name ": device %s not suitable " + pr_err("device %s not suitable " "for any style of array\n", dname); exit(2); @@ -385,10 +376,9 @@ int Create(struct supertype *st, char *mddev, &freesize, verbose >= 0)) { - fprintf(stderr, - Name ": %s is not suitable for " - "this array.\n", - dname); + pr_err("%s is not suitable for " + "this array.\n", + dname); fail = 1; continue; } @@ -401,7 +391,7 @@ int Create(struct supertype *st, char *mddev, if (do_default_chunk) { /* default chunk was just set */ if (verbose > 0) - fprintf(stderr, Name ": chunk size " + pr_err("chunk size " "defaults to %dK\n", chunk); size &= ~(unsigned long long)(chunk - 1); do_default_chunk = 0; @@ -409,7 +399,7 @@ int Create(struct supertype *st, char *mddev, } if (size && freesize < size) { - fprintf(stderr, Name ": %s is smaller than given size." + pr_err("%s is smaller than given size." " %lluK < %lluK + metadata\n", dname, freesize, size); fail = 1; @@ -426,7 +416,7 @@ int Create(struct supertype *st, char *mddev, if (runstop != 1 || verbose >= 0) { int fd = open(dname, O_RDONLY); if (fd <0 ) { - fprintf(stderr, Name ": Cannot open %s: %s\n", + pr_err("Cannot open %s: %s\n", dname, strerror(errno)); fail=1; continue; @@ -451,7 +441,7 @@ int Create(struct supertype *st, char *mddev, level == 1 && (warn & 1024) == 0) { warn |= 1024; - fprintf(stderr, Name ": Note: this array has metadata at the start and\n" + pr_err("Note: this array has metadata at the start and\n" " may not be suitable as a boot device. If you plan to\n" " store '/boot' on this device please ensure that\n" " your boot-loader understands md/v1.x metadata, or use\n" @@ -461,7 +451,7 @@ int Create(struct supertype *st, char *mddev, } } if (raiddisks + sparedisks > st->max_devs) { - fprintf(stderr, Name ": Too many devices:" + pr_err("Too many devices:" " %s metadata only supports %d\n", st->ss->name, st->max_devs); return 1; @@ -469,12 +459,12 @@ int Create(struct supertype *st, char *mddev, if (have_container) info.array.working_disks = raiddisks; if (fail) { - fprintf(stderr, Name ": create aborted\n"); + pr_err("create aborted\n"); return 1; } if (size == 0) { if (mindisc == NULL && !have_container) { - fprintf(stderr, Name ": no size and no drives given - aborting create.\n"); + pr_err("no size and no drives given - aborting create.\n"); return 1; } if (level > 0 || level == LEVEL_MULTIPATH @@ -485,7 +475,7 @@ int Create(struct supertype *st, char *mddev, raiddisks, &chunk, minsize*2, NULL, NULL, 0)) { - fprintf(stderr, Name ": devices too large for RAID level %d\n", level); + pr_err("devices too large for RAID level %d\n", level); return 1; } size = minsize; @@ -496,19 +486,19 @@ int Create(struct supertype *st, char *mddev, */ size &= ~(64ULL-1); if (verbose > 0) - fprintf(stderr, Name ": size set to %lluK\n", size); + pr_err("size set to %lluK\n", size); } } if (!have_container && level > 0 && ((maxsize-size)*100 > maxsize)) { if (runstop != 1 || verbose >= 0) - fprintf(stderr, Name ": largest drive (%s) exceeds size (%lluK) by more than 1%%\n", + pr_err("largest drive (%s) exceeds size (%lluK) by more than 1%%\n", maxdisc, size); warn = 1; } if (st->ss->detail_platform && st->ss->detail_platform(0, 1) != 0) { if (runstop != 1 || verbose >= 0) - fprintf(stderr, Name ": %s unable to enumerate platform support\n" + pr_err("%s unable to enumerate platform support\n" " array may not be compatible with hardware/firmware\n", st->ss->name); warn = 1; @@ -517,12 +507,12 @@ int Create(struct supertype *st, char *mddev, if (warn) { if (runstop!= 1) { if (!ask("Continue creating array? ")) { - fprintf(stderr, Name ": create aborted.\n"); + pr_err("create aborted.\n"); return 1; } } else { if (verbose > 0) - fprintf(stderr, Name ": creation continuing despite oddities due to --run\n"); + pr_err("creation continuing despite oddities due to --run\n"); } } @@ -559,8 +549,7 @@ int Create(struct supertype *st, char *mddev, } if (level <= 0 && first_missing < subdevs * 2) { - fprintf(stderr, - Name ": This level does not support missing devices\n"); + pr_err("This level does not support missing devices\n"); return 1; } @@ -577,7 +566,7 @@ int Create(struct supertype *st, char *mddev, */ if (strncmp(chosen_name, "/dev/md/", 8) == 0 && map_by_name(&map, chosen_name+8) != NULL) { - fprintf(stderr, Name ": Array name %s is in use already.\n", + pr_err("Array name %s is in use already.\n", chosen_name); close(mdfd); map_unlock(&map); @@ -587,14 +576,14 @@ int Create(struct supertype *st, char *mddev, vers = md_get_version(mdfd); if (vers < 9000) { - fprintf(stderr, Name ": Create requires md driver version 0.90.0 or later\n"); + pr_err("Create requires md driver version 0.90.0 or later\n"); goto abort_locked; } else { mdu_array_info_t inf; memset(&inf, 0, sizeof(inf)); ioctl(mdfd, GET_ARRAY_INFO, &inf); if (inf.working_disks != 0) { - fprintf(stderr, Name ": another array by this name" + pr_err("another array by this name" " is already running.\n"); goto abort_locked; } @@ -711,12 +700,12 @@ int Create(struct supertype *st, char *mddev, mdi = sysfs_read(-1, dnum, GET_VERSION); - fprintf(stderr, Name ": Creating array inside " + pr_err("Creating array inside " "%s container %s\n", mdi?mdi->text_version:"managed", path); sysfs_free(mdi); } else - fprintf(stderr, Name ": Defaulting to version" + pr_err("Defaulting to version" " %s metadata\n", info.text_version); } @@ -727,25 +716,25 @@ int Create(struct supertype *st, char *mddev, if (bitmap_file && vers < 9003) { major_num = BITMAP_MAJOR_HOSTENDIAN; #ifdef __BIG_ENDIAN - fprintf(stderr, Name ": Warning - bitmaps created on this kernel are not portable\n" + pr_err("Warning - bitmaps created on this kernel are not portable\n" " between different architectured. Consider upgrading the Linux kernel.\n"); #endif } if (bitmap_file && strcmp(bitmap_file, "internal")==0) { if ((vers%100) < 2) { - fprintf(stderr, Name ": internal bitmaps not supported by this kernel.\n"); + pr_err("internal bitmaps not supported by this kernel.\n"); goto abort; } if (!st->ss->add_internal_bitmap) { - fprintf(stderr, Name ": internal bitmaps not supported with %s metadata\n", + pr_err("internal bitmaps not supported with %s metadata\n", st->ss->name); goto abort; } if (!st->ss->add_internal_bitmap(st, &bitmap_chunk, delay, write_behind, bitmapsize, 1, major_num)) { - fprintf(stderr, Name ": Given bitmap chunk size not supported.\n"); + pr_err("Given bitmap chunk size not supported.\n"); goto abort; } bitmap_file = NULL; @@ -771,13 +760,13 @@ int Create(struct supertype *st, char *mddev, */ container_fd = open_dev_excl(st->container_dev); if (container_fd < 0) { - fprintf(stderr, Name ": Cannot get exclusive " + pr_err("Cannot get exclusive " "open on container - weird.\n"); goto abort; } if (mdmon_running(st->container_dev)) { if (verbose) - fprintf(stderr, Name ": reusing mdmon " + pr_err("reusing mdmon " "for %s.\n", devnum2devname(st->container_dev)); st->update_tail = &st->updates; @@ -786,7 +775,7 @@ int Create(struct supertype *st, char *mddev, } rv = set_array_info(mdfd, st, &info); if (rv) { - fprintf(stderr, Name ": failed to set array info for %s: %s\n", + pr_err("failed to set array info for %s: %s\n", mddev, strerror(errno)); goto abort; } @@ -803,12 +792,12 @@ int Create(struct supertype *st, char *mddev, } bitmap_fd = open(bitmap_file, O_RDWR); if (bitmap_fd < 0) { - fprintf(stderr, Name ": weird: %s cannot be openned\n", + pr_err("weird: %s cannot be openned\n", bitmap_file); goto abort; } if (ioctl(mdfd, SET_BITMAP_FILE, bitmap_fd) < 0) { - fprintf(stderr, Name ": Cannot set bitmap file for %s: %s\n", + pr_err("Cannot set bitmap file for %s: %s\n", mddev, strerror(errno)); goto abort; } @@ -816,7 +805,7 @@ int Create(struct supertype *st, char *mddev, infos = malloc(sizeof(*infos) * total_slots); if (!infos) { - fprintf(stderr, Name ": Unable to allocate memory\n"); + pr_err("Unable to allocate memory\n"); goto abort; } @@ -868,7 +857,7 @@ int Create(struct supertype *st, char *mddev, fd = open(dv->devname, O_RDWR|O_EXCL); if (fd < 0) { - fprintf(stderr, Name ": failed to open %s " + pr_err("failed to open %s " "after earlier success - aborting\n", dv->devname); goto abort; @@ -888,7 +877,7 @@ int Create(struct supertype *st, char *mddev, safe_mode_delay = inf->safe_mode_delay; if (have_container && verbose > 0) - fprintf(stderr, Name ": Using %s for device %d\n", + pr_err("Using %s for device %d\n", map_dev(inf->disk.major, inf->disk.minor, 0), dnum); @@ -905,10 +894,9 @@ int Create(struct supertype *st, char *mddev, rv = add_disk(mdfd, st, &info, inf); if (rv) { - fprintf(stderr, - Name ": ADD_NEW_DISK for %s " - "failed: %s\n", - dv->devname, strerror(errno)); + pr_err("ADD_NEW_DISK for %s " + "failed: %s\n", + dv->devname, strerror(errno)); goto abort; } break; @@ -964,7 +952,7 @@ int Create(struct supertype *st, char *mddev, * create links */ sysfs_uevent(&info, "change"); if (verbose >= 0) - fprintf(stderr, Name ": container %s prepared.\n", mddev); + pr_err("container %s prepared.\n", mddev); wait_for(chosen_name, mdfd); } else if (runstop == 1 || subdevs >= raiddisks) { if (st->ss->external) { @@ -984,8 +972,8 @@ int Create(struct supertype *st, char *mddev, } sysfs_set_safemode(&info, safe_mode_delay); if (err) { - fprintf(stderr, Name ": failed to" - " activate array.\n"); + pr_err("failed to" + " activate array.\n"); ioctl(mdfd, STOP_ARRAY, NULL); goto abort; } @@ -993,18 +981,18 @@ int Create(struct supertype *st, char *mddev, /* param is not actually used */ mdu_param_t param; if (ioctl(mdfd, RUN_ARRAY, ¶m)) { - fprintf(stderr, Name ": RUN_ARRAY failed: %s\n", + pr_err("RUN_ARRAY failed: %s\n", strerror(errno)); if (info.array.chunk_size & (info.array.chunk_size-1)) { - fprintf(stderr, " : Problem may be that " - "chunk size is not a power of 2\n"); + cont_err("Problem may be that " + "chunk size is not a power of 2\n"); } ioctl(mdfd, STOP_ARRAY, NULL); goto abort; } } if (verbose >= 0) - fprintf(stderr, Name ": array %s started.\n", mddev); + pr_err("array %s started.\n", mddev); if (st->ss->external && st->container_dev != NoMdDev) { if (need_mdmon) start_mdmon(st->container_dev); @@ -1014,7 +1002,7 @@ int Create(struct supertype *st, char *mddev, } wait_for(chosen_name, mdfd); } else { - fprintf(stderr, Name ": not starting array - not enough devices.\n"); + pr_err("not starting array - not enough devices.\n"); } close(mdfd); return 0; diff --git a/Detail.c b/Detail.c index 7d5fc27a..f0215502 100644 --- a/Detail.c +++ b/Detail.c @@ -61,29 +61,29 @@ int Detail(char *dev, int brief, int export, int test, char *homehost, char *pre char *avail = NULL; if (fd < 0) { - fprintf(stderr, Name ": cannot open %s: %s\n", + pr_err("cannot open %s: %s\n", dev, strerror(errno)); return rv; } vers = md_get_version(fd); if (vers < 0) { - fprintf(stderr, Name ": %s does not appear to be an md device\n", + pr_err("%s does not appear to be an md device\n", dev); close(fd); return rv; } if (vers < 9000) { - fprintf(stderr, Name ": cannot get detail for md device %s: driver version too old.\n", + pr_err("cannot get detail for md device %s: driver version too old.\n", dev); close(fd); return rv; } if (ioctl(fd, GET_ARRAY_INFO, &array)<0) { if (errno == ENODEV) - fprintf(stderr, Name ": md device %s does not appear to be active.\n", + pr_err("md device %s does not appear to be active.\n", dev); else - fprintf(stderr, Name ": cannot get array detail for %s: %s\n", + pr_err("cannot get array detail for %s: %s\n", dev, strerror(errno)); close(fd); return rv; @@ -239,7 +239,7 @@ int Detail(char *dev, int brief, int export, int test, char *homehost, char *pre disk.number = d; if (ioctl(fd, GET_DISK_INFO, &disk) < 0) { if (d < array.raid_disks) - fprintf(stderr, Name ": cannot get device detail for device %d: %s\n", + pr_err("cannot get device detail for device %d: %s\n", d, strerror(errno)); continue; } @@ -617,11 +617,11 @@ int Detail_Platform(struct superswitch *ss, int scan, int verbose) err = ss->detail_platform(verbose, 0); else if (ss) { if (verbose) - fprintf(stderr, Name ": %s metadata is platform independent\n", + pr_err("%s metadata is platform independent\n", ss->name ? : "[no name]"); } else if (!scan) { if (verbose) - fprintf(stderr, Name ": specify a metadata type or --scan\n"); + pr_err("specify a metadata type or --scan\n"); } if (!scan) @@ -633,11 +633,11 @@ int Detail_Platform(struct superswitch *ss, int scan, int verbose) if (meta == ss) continue; if (verbose) - fprintf(stderr, Name ": checking metadata %s\n", + pr_err("checking metadata %s\n", meta->name ? : "[no name]"); if (!meta->detail_platform) { if (verbose) - fprintf(stderr, Name ": %s metadata is platform independent\n", + pr_err("%s metadata is platform independent\n", meta->name ? : "[no name]"); } else err |= meta->detail_platform(verbose, 0); diff --git a/Examine.c b/Examine.c index 5d71e537..6131e367 100644 --- a/Examine.c +++ b/Examine.c @@ -69,8 +69,8 @@ int Examine(struct mddev_dev *devlist, int brief, int export, int scan, fd = dev_open(devlist->devname, O_RDONLY); if (fd < 0) { if (!scan) { - fprintf(stderr,Name ": cannot open %s: %s\n", - devlist->devname, strerror(errno)); + pr_err("cannot open %s: %s\n", + devlist->devname, strerror(errno)); rv = 1; } err = 1; @@ -102,7 +102,7 @@ int Examine(struct mddev_dev *devlist, int brief, int export, int scan, st->ignore_hw_compat = 0; } else { if (!brief) { - fprintf(stderr, Name ": No md superblock detected on %s.\n", devlist->devname); + pr_err("No md superblock detected on %s.\n", devlist->devname); rv = 1; } err = 1; @@ -119,7 +119,7 @@ int Examine(struct mddev_dev *devlist, int brief, int export, int scan, if (brief && st->ss->brief_examine_super == NULL) { if (!scan) - fprintf(stderr, Name ": No brief listing for %s on %s\n", + pr_err("No brief listing for %s on %s\n", st->ss->name, devlist->devname); } else if (brief) { struct array *ap; diff --git a/Grow.c b/Grow.c index 8e3b5c0f..50effc7f 100644 --- a/Grow.c +++ b/Grow.c @@ -51,8 +51,7 @@ int restore_backup(struct supertype *st, dprintf("Called restore_backup()\n"); fdlist = malloc(sizeof(int) * disk_count); if (fdlist == NULL) { - fprintf(stderr, - Name ": cannot allocate memory for disk list\n"); + pr_err("cannot allocate memory for disk list\n"); return 1; } for (i = 0; i < next_spare; i++) @@ -84,10 +83,10 @@ int restore_backup(struct supertype *st, } free(fdlist); if (err) { - fprintf(stderr, Name ": Failed to restore critical" - " section for reshape - sorry.\n"); + pr_err("Failed to restore critical" + " section for reshape - sorry.\n"); if (!backup_file) - fprintf(stderr, Name ": Possibly you need" + pr_err("Possibly you need" " to specify a --backup-file\n"); return 1; } @@ -115,23 +114,23 @@ int Grow_Add_device(char *devname, int fd, char *newdev) char *subarray = NULL; if (ioctl(fd, GET_ARRAY_INFO, &info.array) < 0) { - fprintf(stderr, Name ": cannot get array info for %s\n", devname); + pr_err("cannot get array info for %s\n", devname); return 1; } if (info.array.level != -1) { - fprintf(stderr, Name ": can only add devices to linear arrays\n"); + pr_err("can only add devices to linear arrays\n"); return 1; } st = super_by_fd(fd, &subarray); if (!st) { - fprintf(stderr, Name ": cannot handle arrays with superblock version %d\n", info.array.major_version); + pr_err("cannot handle arrays with superblock version %d\n", info.array.major_version); return 1; } if (subarray) { - fprintf(stderr, Name ": Cannot grow linear sub-arrays yet\n"); + pr_err("Cannot grow linear sub-arrays yet\n"); free(subarray); free(st); return 1; @@ -139,13 +138,13 @@ int Grow_Add_device(char *devname, int fd, char *newdev) nfd = open(newdev, O_RDWR|O_EXCL|O_DIRECT); if (nfd < 0) { - fprintf(stderr, Name ": cannot open %s\n", newdev); + pr_err("cannot open %s\n", newdev); free(st); return 1; } fstat(nfd, &stb); if ((stb.st_mode & S_IFMT) != S_IFBLK) { - fprintf(stderr, Name ": %s is not a block device!\n", newdev); + pr_err("%s is not a block device!\n", newdev); close(nfd); free(st); return 1; @@ -159,7 +158,7 @@ int Grow_Add_device(char *devname, int fd, char *newdev) disk.number = d; if (ioctl(fd, GET_DISK_INFO, &disk) < 0) { - fprintf(stderr, Name ": cannot get device detail for device %d\n", + pr_err("cannot get device detail for device %d\n", d); close(nfd); free(st); @@ -167,7 +166,7 @@ int Grow_Add_device(char *devname, int fd, char *newdev) } dv = map_dev(disk.major, disk.minor, 1); if (!dv) { - fprintf(stderr, Name ": cannot find device file for device %d\n", + pr_err("cannot find device file for device %d\n", d); close(nfd); free(st); @@ -175,14 +174,14 @@ int Grow_Add_device(char *devname, int fd, char *newdev) } fd2 = dev_open(dv, O_RDWR); if (fd2 < 0) { - fprintf(stderr, Name ": cannot open device file %s\n", dv); + pr_err("cannot open device file %s\n", dv); close(nfd); free(st); return 1; } if (st->ss->load_super(st, fd2, NULL)) { - fprintf(stderr, Name ": cannot find super block on %s\n", dv); + pr_err("cannot find super block on %s\n", dv); close(nfd); close(fd2); free(st); @@ -203,7 +202,7 @@ int Grow_Add_device(char *devname, int fd, char *newdev) 0, 0, NULL); if (st->ss->store_super(st, nfd)) { - fprintf(stderr, Name ": Cannot store new superblock on %s\n", + pr_err("Cannot store new superblock on %s\n", newdev); close(nfd); return 1; @@ -211,7 +210,7 @@ int Grow_Add_device(char *devname, int fd, char *newdev) close(nfd); if (ioctl(fd, ADD_NEW_DISK, &info.disk) != 0) { - fprintf(stderr, Name ": Cannot add new disk to this array\n"); + pr_err("Cannot add new disk to this array\n"); return 1; } /* Well, that seems to have worked. @@ -219,7 +218,7 @@ int Grow_Add_device(char *devname, int fd, char *newdev) */ if (ioctl(fd, GET_ARRAY_INFO, &info.array) < 0) { - fprintf(stderr, Name ": cannot get array info for %s\n", devname); + pr_err("cannot get array info for %s\n", devname); return 1; } @@ -230,23 +229,23 @@ int Grow_Add_device(char *devname, int fd, char *newdev) disk.number = d; if (ioctl(fd, GET_DISK_INFO, &disk) < 0) { - fprintf(stderr, Name ": cannot get device detail for device %d\n", + pr_err("cannot get device detail for device %d\n", d); return 1; } dv = map_dev(disk.major, disk.minor, 1); if (!dv) { - fprintf(stderr, Name ": cannot find device file for device %d\n", + pr_err("cannot find device file for device %d\n", d); return 1; } fd2 = dev_open(dv, O_RDWR); if (fd2 < 0) { - fprintf(stderr, Name ": cannot open device file %s\n", dv); + pr_err("cannot open device file %s\n", dv); return 1; } if (st->ss->load_super(st, fd2, NULL)) { - fprintf(stderr, Name ": cannot find super block on %s\n", dv); + pr_err("cannot find super block on %s\n", dv); close(fd); return 1; } @@ -259,7 +258,7 @@ int Grow_Add_device(char *devname, int fd, char *newdev) 0, 0, NULL); if (st->ss->store_super(st, fd2)) { - fprintf(stderr, Name ": Cannot store new superblock on %s\n", dv); + pr_err("Cannot store new superblock on %s\n", dv); close(fd2); return 1; } @@ -290,7 +289,7 @@ int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay, int if (vers < 9003) { major = BITMAP_MAJOR_HOSTENDIAN; - fprintf(stderr, Name ": Warning - bitmaps created on this kernel" + pr_err("Warning - bitmaps created on this kernel" " are not portable\n" " between different architectures. Consider upgrading" " the Linux kernel.\n"); @@ -298,48 +297,48 @@ int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay, int if (ioctl(fd, GET_BITMAP_FILE, &bmf) != 0) { if (errno == ENOMEM) - fprintf(stderr, Name ": Memory allocation failure.\n"); + pr_err("Memory allocation failure.\n"); else - fprintf(stderr, Name ": bitmaps not supported by this kernel.\n"); + pr_err("bitmaps not supported by this kernel.\n"); return 1; } if (bmf.pathname[0]) { if (strcmp(file,"none")==0) { if (ioctl(fd, SET_BITMAP_FILE, -1)!= 0) { - fprintf(stderr, Name ": failed to remove bitmap %s\n", + pr_err("failed to remove bitmap %s\n", bmf.pathname); return 1; } return 0; } - fprintf(stderr, Name ": %s already has a bitmap (%s)\n", + pr_err("%s already has a bitmap (%s)\n", devname, bmf.pathname); return 1; } if (ioctl(fd, GET_ARRAY_INFO, &array) != 0) { - fprintf(stderr, Name ": cannot get array status for %s\n", devname); + pr_err("cannot get array status for %s\n", devname); return 1; } if (array.state & (1<ss->add_internal_bitmap == NULL) { - fprintf(stderr, Name ": Internal bitmaps not supported " + pr_err("Internal bitmaps not supported " "with %s metadata\n", st->ss->name); return 1; } @@ -412,8 +411,8 @@ int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay, int ) st->ss->write_bitmap(st, fd2); else { - fprintf(stderr, Name ": failed " - "to create internal bitmap - chunksize problem.\n"); + pr_err("failed " + "to create internal bitmap - chunksize problem.\n"); close(fd2); return 1; } @@ -432,10 +431,9 @@ int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay, int } if (rv < 0) { if (errno == EBUSY) - fprintf(stderr, Name - ": Cannot add bitmap while array is" - " resyncing or reshaping etc.\n"); - fprintf(stderr, Name ": failed to set internal bitmap.\n"); + pr_err("Cannot add bitmap while array is" + " resyncing or reshaping etc.\n"); + pr_err("failed to set internal bitmap.\n"); return 1; } } else { @@ -468,7 +466,7 @@ int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay, int } } if (d == max_devs) { - fprintf(stderr, Name ": cannot find UUID for array!\n"); + pr_err("cannot find UUID for array!\n"); return 1; } if (CreateBitmap(file, force, (char*)uuid, chunk, @@ -477,17 +475,16 @@ int Grow_addbitmap(char *devname, int fd, char *file, int chunk, int delay, int } bitmap_fd = open(file, O_RDWR); if (bitmap_fd < 0) { - fprintf(stderr, Name ": weird: %s cannot be opened\n", + pr_err("weird: %s cannot be opened\n", file); return 1; } if (ioctl(fd, SET_BITMAP_FILE, bitmap_fd) < 0) { int err = errno; if (errno == EBUSY) - fprintf(stderr, Name - ": Cannot add bitmap while array is" - " resyncing or reshaping etc.\n"); - fprintf(stderr, Name ": Cannot set bitmap file for %s: %s\n", + pr_err("Cannot add bitmap while array is" + " resyncing or reshaping etc.\n"); + pr_err("Cannot set bitmap file for %s: %s\n", devname, strerror(err)); return 1; } @@ -568,7 +565,7 @@ static int freeze_container(struct supertype *st) fmt_devname(container, container_dev); if (block_monitor(container, 1)) { - fprintf(stderr, Name ": failed to freeze container\n"); + pr_err("failed to freeze container\n"); return -2; } @@ -655,7 +652,7 @@ static int reshape_super(struct supertype *st, long long size, int level, return 0; if (!st->ss->reshape_super || !st->ss->manage_reshape) { - fprintf(stderr, Name ": %s metadata does not support reshape\n", + pr_err("%s metadata does not support reshape\n", st->ss->name); return 1; } @@ -861,9 +858,8 @@ int reshape_prepare_fdlist(char *devname, = dev_open(dn, O_RDONLY); offsets[sd->disk.raid_disk] = sd->data_offset*512; if (fdlist[sd->disk.raid_disk] < 0) { - fprintf(stderr, - Name ": %s: cannot open component %s\n", - devname, dn ? dn : "-unknown-"); + pr_err("%s: cannot open component %s\n", + devname, dn ? dn : "-unknown-"); d = -1; goto release; } @@ -874,7 +870,7 @@ int reshape_prepare_fdlist(char *devname, fdlist[d] = dev_open(dn, O_RDWR); offsets[d] = (sd->data_offset + sra->component_size - blocks - 8)*512; if (fdlist[d] < 0) { - fprintf(stderr, Name ": %s: cannot open component %s\n", + pr_err("%s: cannot open component %s\n", devname, dn ? dn : "-unknown-"); d = -1; goto release; @@ -905,7 +901,7 @@ int reshape_open_backup_file(char *backup_file, S_IRUSR | S_IWUSR); *offsets = 8 * 512; if (*fdlist < 0) { - fprintf(stderr, Name ": %s: cannot create backup file %s: %s\n", + pr_err("%s: cannot create backup file %s: %s\n", devname, backup_file, strerror(errno)); return 0; } @@ -918,7 +914,7 @@ int reshape_open_backup_file(char *backup_file, dev = stb.st_dev; fstat(fd, &stb); if (stb.st_rdev == dev) { - fprintf(stderr, Name ": backup file must NOT be" + pr_err("backup file must NOT be" " on the array being reshaped.\n"); close(*fdlist); return 0; @@ -927,14 +923,14 @@ int reshape_open_backup_file(char *backup_file, memset(buf, 0, 512); for (i=0; i < blocks + 8 ; i++) { if (write(*fdlist, buf, 512) != 512) { - fprintf(stderr, Name ": %s: cannot create" + pr_err("%s: cannot create" " backup file %s: %s\n", devname, backup_file, strerror(errno)); return 0; } } if (fsync(*fdlist) != 0) { - fprintf(stderr, Name ": %s: cannot create backup file %s: %s\n", + pr_err("%s: cannot create backup file %s: %s\n", devname, backup_file, strerror(errno)); return 0; } @@ -1476,14 +1472,14 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file, struct mdinfo *sra; if (ioctl(fd, GET_ARRAY_INFO, &array) < 0) { - fprintf(stderr, Name ": %s is not an active md array - aborting\n", + pr_err("%s is not an active md array - aborting\n", devname); return 1; } if (size >= 0 && (chunksize || level!= UnSet || layout_str || raid_disks)) { - fprintf(stderr, Name ": cannot change component size at the same time " + pr_err("cannot change component size at the same time " "as other changes.\n" " Change size first, then check data is intact before " "making other changes.\n"); @@ -1493,18 +1489,18 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file, if (raid_disks && raid_disks < array.raid_disks && array.level > 1 && get_linux_version() < 2006032 && !check_env("MDADM_FORCE_FEWER")) { - fprintf(stderr, Name ": reducing the number of devices is not safe before Linux 2.6.32\n" + pr_err("reducing the number of devices is not safe before Linux 2.6.32\n" " Please use a newer kernel\n"); return 1; } st = super_by_fd(fd, &subarray); if (!st) { - fprintf(stderr, Name ": Unable to determine metadata format for %s\n", devname); + pr_err("Unable to determine metadata format for %s\n", devname); return 1; } if (raid_disks > st->max_devs) { - fprintf(stderr, Name ": Cannot increase raid-disks on this array" + pr_err("Cannot increase raid-disks on this array" " beyond %d\n", st->max_devs); return 1; } @@ -1527,7 +1523,7 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file, fd = cfd; } if (cfd < 0) { - fprintf(stderr, Name ": Unable to open container for %s\n", + pr_err("Unable to open container for %s\n", devname); free(subarray); return 1; @@ -1539,7 +1535,7 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file, rv = st->ss->load_container(st, cfd, NULL); if (rv) { - fprintf(stderr, Name ": Cannot read superblock for %s\n", + pr_err("Cannot read superblock for %s\n", devname); free(subarray); return 1; @@ -1563,11 +1559,10 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file, & (1< array.raid_disks && array.spare_disks +added_disks < (raid_disks - array.raid_disks) && !force) { - fprintf(stderr, - Name ": Need %d spare%s to avoid degraded array," - " and only have %d.\n" - " Use --force to over-ride this check.\n", - raid_disks - array.raid_disks, - raid_disks - array.raid_disks == 1 ? "" : "s", - array.spare_disks + added_disks); + pr_err("Need %d spare%s to avoid degraded array," + " and only have %d.\n" + " Use --force to over-ride this check.\n", + raid_disks - array.raid_disks, + raid_disks - array.raid_disks == 1 ? "" : "s", + array.spare_disks + added_disks); return 1; } @@ -1603,7 +1597,7 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file, sra->array.level = LEVEL_CONTAINER; } } else { - fprintf(stderr, Name ": failed to read sysfs parameters for %s\n", + pr_err("failed to read sysfs parameters for %s\n", devname); return 1; } @@ -1613,7 +1607,7 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file, sysfs_free(sra); return 1; } else if (frozen < 0) { - fprintf(stderr, Name ": %s is performing resync/recovery and cannot" + pr_err("%s is performing resync/recovery and cannot" " be reshaped\n", devname); sysfs_free(sra); return 1; @@ -1686,12 +1680,12 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file, } } if (rv) { - fprintf(stderr, Name ": Cannot set size on " + pr_err("Cannot set size on " "array members.\n"); goto size_change_error; } if (min_csize && size > min_csize) { - fprintf(stderr, Name ": Cannot safely make this array " + pr_err("Cannot safely make this array " "use more than 2TB per device on this kernel.\n"); rv = 1; goto size_change_error; @@ -1700,8 +1694,8 @@ int Grow_reshape(char *devname, int fd, int quiet, char *backup_file, /* Don't let the kernel choose a size - it will get * it wrong */ - fprintf(stderr, Name ": Limited v0.90 array to " - "2TB per device\n"); + pr_err("Limited v0.90 array to " + "2TB per device\n"); size = min_csize; } if (st->ss->external) { @@ -1766,11 +1760,11 @@ size_change_error: ROLLBACK_METADATA_CHANGES, !quiet) == 0) sync_metadata(st); - fprintf(stderr, Name ": Cannot set device size for %s: %s\n", + pr_err("Cannot set device size for %s: %s\n", devname, strerror(err)); if (err == EBUSY && (array.state & (1<= 16) { - fprintf(stderr, Name - ": %s has a non-standard layout. If you" - " wish to preserve this\n" - " during the reshape, please specify" - " --layout=preserve\n" - " If you want to change it, specify a" - " layout or use --layout=normalise\n", - devname); + pr_err("%s has a non-standard layout. If you" + " wish to preserve this\n", devname); + cont_err("during the reshape, please specify" + " --layout=preserve\n"); + cont_err("If you want to change it, specify a" + " layout or use --layout=normalise\n"); rv = 1; goto release; } @@ -1884,9 +1876,8 @@ size_change_error: info.new_layout = map_name(r6layout, l); } } else { - fprintf(stderr, Name - ": %s is only meaningful when reshaping" - " a RAID6 array.\n", layout_str); + pr_err("%s is only meaningful when reshaping" + " a RAID6 array.\n", layout_str); rv = 1; goto release; } @@ -1908,9 +1899,8 @@ size_change_error: strcat(l, "-6"); info.new_layout = map_name(r6layout, l); } else { - fprintf(stderr, Name - ": %s in only meaningful when reshaping" - " to RAID6\n", layout_str); + pr_err("%s in only meaningful when reshaping" + " to RAID6\n", layout_str); rv = 1; goto release; } @@ -1932,13 +1922,13 @@ size_change_error: info.new_layout = parse_layout_faulty(layout_str); break; default: - fprintf(stderr, Name ": layout not meaningful" + pr_err("layout not meaningful" " with this level\n"); rv = 1; goto release; } if (info.new_layout == UnSet) { - fprintf(stderr, Name ": layout %s not understood" + pr_err("layout %s not understood" " for this level\n", layout_str); rv = 1; @@ -1948,15 +1938,15 @@ size_change_error: if (array.level == LEVEL_FAULTY) { if (level != UnSet && level != array.level) { - fprintf(stderr, Name ": cannot change level of Faulty device\n"); + pr_err("cannot change level of Faulty device\n"); rv =1 ; } if (chunksize) { - fprintf(stderr, Name ": cannot set chunksize of Faulty device\n"); + pr_err("cannot set chunksize of Faulty device\n"); rv =1 ; } if (raid_disks && raid_disks != 1) { - fprintf(stderr, Name ": cannot set raid_disks of Faulty device\n"); + pr_err("cannot set raid_disks of Faulty device\n"); rv =1 ; } if (layout_str) { @@ -1966,7 +1956,7 @@ size_change_error: } array.layout = info.new_layout; if (ioctl(fd, SET_ARRAY_INFO, &array) != 0) { - fprintf(stderr, Name ": failed to set new layout\n"); + pr_err("failed to set new layout\n"); rv = 1; } else if (!quiet) printf("layout for %s set to %d\n", @@ -2056,11 +2046,11 @@ static int verify_reshape_position(struct mdinfo *info, int level) info->reshape_progress = position; ret_val = 1; } else if (info->reshape_progress > position) { - fprintf(stderr, Name ": Fatal error: array " - "reshape was not properly frozen " - "(expected reshape position is %llu, " - "but reshape progress is %llu.\n", - position, info->reshape_progress); + pr_err("Fatal error: array " + "reshape was not properly frozen " + "(expected reshape position is %llu, " + "but reshape progress is %llu.\n", + position, info->reshape_progress); ret_val = -1; } else { dprintf("Reshape position in md and metadata " @@ -2134,7 +2124,7 @@ static int reshape_array(char *container, int fd, char *devname, } else msg = analyse_change(info, &reshape); if (msg) { - fprintf(stderr, Name ": %s\n", msg); + pr_err("%s\n", msg); goto release; } if (restart && @@ -2142,7 +2132,7 @@ static int reshape_array(char *container, int fd, char *devname, reshape.before.layout != info->array.layout || reshape.before.data_disks + reshape.parity != info->array.raid_disks - max(0, info->delta_disks))) { - fprintf(stderr, Name ": reshape info is not in native format -" + pr_err("reshape info is not in native format -" " cannot continue.\n"); goto release; } @@ -2182,13 +2172,12 @@ static int reshape_array(char *container, int fd, char *devname, if (!force && info->new_level > 1 && info->array.level > 1 && spares_needed > info->array.spare_disks + added_disks) { - fprintf(stderr, - Name ": Need %d spare%s to avoid degraded array," - " and only have %d.\n" - " Use --force to over-ride this check.\n", - spares_needed, - spares_needed == 1 ? "" : "s", - info->array.spare_disks + added_disks); + pr_err("Need %d spare%s to avoid degraded array," + " and only have %d.\n" + " Use --force to over-ride this check.\n", + spares_needed, + spares_needed == 1 ? "" : "s", + info->array.spare_disks + added_disks); goto release; } /* Check we have enough spares to not fail */ @@ -2197,12 +2186,11 @@ static int reshape_array(char *container, int fd, char *devname, - array.raid_disks; if ((info->new_level > 1 || info->new_level == 0) && spares_needed > info->array.spare_disks +added_disks) { - fprintf(stderr, - Name ": Need %d spare%s to create working array," - " and only have %d.\n", - spares_needed, - spares_needed == 1 ? "" : "s", - info->array.spare_disks + added_disks); + pr_err("Need %d spare%s to create working array," + " and only have %d.\n", + spares_needed, + spares_needed == 1 ? "" : "s", + info->array.spare_disks + added_disks); goto release; } @@ -2215,16 +2203,16 @@ static int reshape_array(char *container, int fd, char *devname, err = sysfs_set_str(info, NULL, "level", c); if (err) { err = errno; - fprintf(stderr, Name ": %s: could not set level to %s\n", + pr_err("%s: could not set level to %s\n", devname, c); if (err == EBUSY && (info->array.state & (1<new_layout != array.layout) { array.layout = info->new_layout; if (ioctl(fd, SET_ARRAY_INFO, &array) != 0) { - fprintf(stderr, Name ": failed to set new layout\n"); + pr_err("failed to set new layout\n"); goto release; } else if (!quiet) printf("layout for %s set to %d\n", @@ -2310,7 +2298,7 @@ static int reshape_array(char *container, int fd, char *devname, array.raid_disks != (info->array.raid_disks + info->delta_disks)) { array.raid_disks += info->delta_disks; if (ioctl(fd, SET_ARRAY_INFO, &array) != 0) { - fprintf(stderr, Name ": failed to set raid disks\n"); + pr_err("failed to set raid disks\n"); goto release; } else if (!quiet) { printf("raid_disks for %s set to %d\n", @@ -2321,7 +2309,7 @@ static int reshape_array(char *container, int fd, char *devname, info->new_chunk != array.chunk_size) { if (sysfs_set_num(info, NULL, "chunk_size", info->new_chunk) != 0) { - fprintf(stderr, Name ": failed to set chunk size\n"); + pr_err("failed to set chunk size\n"); goto release; } else if (!quiet) printf("chunk size for %s set to %d\n", @@ -2368,11 +2356,10 @@ started: /* Check that we can hold all the data */ get_dev_size(fd, NULL, &array_size); if (reshape.new_size < (array_size/512)) { - fprintf(stderr, - Name ": this change will reduce the size of the array.\n" - " use --grow --array-size first to truncate array.\n" - " e.g. mdadm --grow %s --array-size %llu\n", - devname, reshape.new_size/2); + pr_err("this change will reduce the size of the array.\n" + " use --grow --array-size first to truncate array.\n" + " e.g. mdadm --grow %s --array-size %llu\n", + devname, reshape.new_size/2); goto release; } @@ -2380,7 +2367,7 @@ started: GET_COMPONENT|GET_DEVS|GET_OFFSET|GET_STATE|GET_CHUNK| GET_CACHE); if (!sra) { - fprintf(stderr, Name ": %s: Cannot get array details from sysfs\n", + pr_err("%s: Cannot get array details from sysfs\n", devname); goto release; } @@ -2399,11 +2386,11 @@ started: blocks < 16*1024*2) blocks *= 2; } else - fprintf(stderr, Name ": Need to backup %luK of critical " + pr_err("Need to backup %luK of critical " "section..\n", blocks/2); if (blocks >= sra->component_size/2) { - fprintf(stderr, Name ": %s: Something wrong" + pr_err("%s: Something wrong" " - reshape aborted\n", devname); goto release; @@ -2417,7 +2404,7 @@ started: fdlist = malloc((1+nrdisks) * sizeof(int)); offsets = malloc((1+nrdisks) * sizeof(offsets[0])); if (!fdlist || !offsets) { - fprintf(stderr, Name ": malloc failed: grow aborted\n"); + pr_err("malloc failed: grow aborted\n"); goto release; } @@ -2433,11 +2420,11 @@ started: if (backup_file == NULL) { if (reshape.after.data_disks <= reshape.before.data_disks) { - fprintf(stderr, Name ": %s: Cannot grow - " + pr_err("%s: Cannot grow - " "need backup-file\n", devname); goto release; } else if (sra->array.spare_disks == 0) { - fprintf(stderr, Name ": %s: Cannot grow - " + pr_err("%s: Cannot grow - " "need a spare or backup-file to backup " "critical section\n", devname); goto release; @@ -2506,15 +2493,13 @@ started: ioctl(fd, SET_ARRAY_INFO, &array) != 0) { int err = errno; - fprintf(stderr, - Name ": Cannot set device shape for %s: %s\n", - devname, strerror(errno)); + pr_err("Cannot set device shape for %s: %s\n", + devname, strerror(errno)); if (err == EBUSY && (array.state & (1<reshape_progress); return 1; @@ -2572,7 +2555,7 @@ started: */ switch(forked ? 0 : fork()) { case -1: - fprintf(stderr, Name ": Cannot run child to monitor reshape: %s\n", + pr_err("Cannot run child to monitor reshape: %s\n", strerror(errno)); abort_reshape(sra); goto release; @@ -2655,9 +2638,8 @@ started: if (c) { err = sysfs_set_str(sra, NULL, "level", c); if (err) - fprintf(stderr, Name\ - ": %s: could not set level " - "to %s\n", devname, c); + pr_err("%s: could not set level " + "to %s\n", devname, c); } if (info->new_level == 0) st->update_tail = NULL; @@ -2675,7 +2657,7 @@ release: if (orig_level != UnSet && sra) { c = map_num(pers, orig_level); if (c && sysfs_set_str(sra, NULL, "level", c) == 0) - fprintf(stderr, Name ": aborting level change\n"); + pr_err("aborting level change\n"); } sysfs_free(sra); if (!forked) @@ -2768,7 +2750,7 @@ int reshape_container(char *container, char *devname, if (!mdstat) continue; if (mdstat->active == 0) { - fprintf(stderr, Name ": Skipping inactive " + pr_err("Skipping inactive " "array md%i.\n", mdstat->devnum); free_mdstat(mdstat); mdstat = NULL; @@ -3496,7 +3478,7 @@ int child_monitor(int afd, struct mdinfo *sra, struct reshape *reshape, break; } if (!sd) { - fprintf(stderr, Name ": Cannot find a superblock\n"); + pr_err("Cannot find a superblock\n"); return 0; } @@ -3691,7 +3673,7 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, int cnt if (i == old_disks-1) { fd = open(backup_file, O_RDONLY); if (fd<0) { - fprintf(stderr, Name ": backup file %s inaccessible: %s\n", + pr_err("backup file %s inaccessible: %s\n", backup_file, strerror(errno)); continue; } @@ -3709,7 +3691,7 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, int cnt if (lseek64(fd, (dinfo.data_offset + dinfo.component_size - 8) <<9, 0) < 0) { - fprintf(stderr, Name ": Cannot seek on device %d\n", i); + pr_err("Cannot seek on device %d\n", i); continue; /* Cannot seek */ } sprintf(namebuf, "device-%d", i); @@ -3717,29 +3699,29 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, int cnt } if (read(fd, &bsb, sizeof(bsb)) != sizeof(bsb)) { if (verbose) - fprintf(stderr, Name ": Cannot read from %s\n", devname); + pr_err("Cannot read from %s\n", devname); continue; /* Cannot read */ } if (memcmp(bsb.magic, "md_backup_data-1", 16) != 0 && memcmp(bsb.magic, "md_backup_data-2", 16) != 0) { if (verbose) - fprintf(stderr, Name ": No backup metadata on %s\n", devname); + pr_err("No backup metadata on %s\n", devname); continue; } if (bsb.sb_csum != bsb_csum((char*)&bsb, ((char*)&bsb.sb_csum)-((char*)&bsb))) { if (verbose) - fprintf(stderr, Name ": Bad backup-metadata checksum on %s\n", devname); + pr_err("Bad backup-metadata checksum on %s\n", devname); continue; /* bad checksum */ } if (memcmp(bsb.magic, "md_backup_data-2", 16) == 0 && bsb.sb_csum2 != bsb_csum((char*)&bsb, ((char*)&bsb.sb_csum2)-((char*)&bsb))) { if (verbose) - fprintf(stderr, Name ": Bad backup-metadata checksum2 on %s\n", devname); + pr_err("Bad backup-metadata checksum2 on %s\n", devname); continue; /* Bad second checksum */ } if (memcmp(bsb.set_uuid,info->uuid, 16) != 0) { if (verbose) - fprintf(stderr, Name ": Wrong uuid on backup-metadata on %s\n", devname); + pr_err("Wrong uuid on backup-metadata on %s\n", devname); continue; /* Wrong uuid */ } @@ -3750,13 +3732,13 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, int cnt if (info->array.utime > (int)__le64_to_cpu(bsb.mtime) + 2*60*60 || info->array.utime < (int)__le64_to_cpu(bsb.mtime) - 10*60) { if (check_env("MDADM_GROW_ALLOW_OLD")) { - fprintf(stderr, Name ": accepting backup with timestamp %lu " + pr_err("accepting backup with timestamp %lu " "for array with timestamp %lu\n", (unsigned long)__le64_to_cpu(bsb.mtime), (unsigned long)info->array.utime); } else { if (verbose) - fprintf(stderr, Name ": too-old timestamp on " + pr_err("too-old timestamp on " "backup-metadata on %s\n", devname); continue; /* time stamp is too bad */ } @@ -3772,8 +3754,7 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, int cnt < info->reshape_progress) { nonew: if (verbose) - fprintf(stderr, Name - ": backup-metadata found on %s but is not needed\n", devname); + pr_err("backup-metadata found on %s but is not needed\n", devname); continue; /* No new data here */ } } else { @@ -3807,9 +3788,8 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, int cnt if (lseek64(fd, __le64_to_cpu(bsb.devstart)*512, 0)< 0) { second_fail: if (verbose) - fprintf(stderr, Name - ": Failed to verify secondary backup-metadata block on %s\n", - devname); + pr_err("Failed to verify secondary backup-metadata block on %s\n", + devname); continue; /* Cannot seek */ } /* There should be a duplicate backup superblock 4k before here */ @@ -3847,7 +3827,7 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, int cnt __le64_to_cpu(bsb.length)*512, NULL)) { /* didn't succeed, so giveup */ if (verbose) - fprintf(stderr, Name ": Error restoring backup from %s\n", + pr_err("Error restoring backup from %s\n", devname); free(offsets); return 1; @@ -3865,7 +3845,7 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, int cnt __le64_to_cpu(bsb.length2)*512, NULL)) { /* didn't succeed, so giveup */ if (verbose) - fprintf(stderr, Name ": Error restoring second backup from %s\n", + pr_err("Error restoring second backup from %s\n", devname); free(offsets); return 1; @@ -3964,7 +3944,7 @@ int Grow_restart(struct supertype *st, struct mdinfo *info, int *fdlist, int cnt } /* needed to recover critical section! */ if (verbose) - fprintf(stderr, Name ": Failed to find backup of critical section\n"); + pr_err("Failed to find backup of critical section\n"); return 1; } @@ -3987,16 +3967,15 @@ int Grow_continue_command(char *devname, int fd, st = super_by_fd(fd, &subarray); if (!st || !st->ss) { - fprintf(stderr, - Name ": Unable to determine metadata format for %s\n", - devname); + pr_err("Unable to determine metadata format for %s\n", + devname); return 1; } dprintf("Grow continue is run for "); if (st->ss->external == 0) { dprintf("native array (%s)\n", devname); if (ioctl(fd, GET_ARRAY_INFO, &array) < 0) { - fprintf(stderr, Name ": %s is not an active md array -" + pr_err("%s is not an active md array -" " aborting\n", devname); ret_val = 1; goto Grow_continue_command_exit; @@ -4018,7 +3997,7 @@ int Grow_continue_command(char *devname, int fd, fd = cfd; } if (cfd < 0) { - fprintf(stderr, Name ": Unable to open container " + pr_err("Unable to open container " "for %s\n", devname); ret_val = 1; goto Grow_continue_command_exit; @@ -4029,9 +4008,8 @@ int Grow_continue_command(char *devname, int fd, */ ret_val = st->ss->load_container(st, cfd, NULL); if (ret_val) { - fprintf(stderr, - Name ": Cannot read superblock for %s\n", - devname); + pr_err("Cannot read superblock for %s\n", + devname); ret_val = 1; goto Grow_continue_command_exit; } @@ -4057,11 +4035,10 @@ int Grow_continue_command(char *devname, int fd, allow_reshape = 0; if (!allow_reshape) { - fprintf(stderr, Name - ": cannot continue reshape of an array" - " in container with unsupported" - " metadata: %s(%s)\n", - devname, buf); + pr_err("cannot continue reshape of an array" + " in container with unsupported" + " metadata: %s(%s)\n", + devname, buf); ret_val = 1; goto Grow_continue_command_exit; } @@ -4071,7 +4048,7 @@ int Grow_continue_command(char *devname, int fd, if (!mdstat) continue; if (mdstat->active == 0) { - fprintf(stderr, Name ": Skipping inactive " + pr_err("Skipping inactive " "array md%i.\n", mdstat->devnum); free_mdstat(mdstat); mdstat = NULL; @@ -4080,15 +4057,14 @@ int Grow_continue_command(char *devname, int fd, break; } if (!content) { - fprintf(stderr, - Name ": Unable to determine reshaped " - "array for %s\n", devname); + pr_err("Unable to determine reshaped " + "array for %s\n", devname); ret_val = 1; goto Grow_continue_command_exit; } fd2 = open_dev(mdstat->devnum); if (fd2 < 0) { - fprintf(stderr, Name ": cannot open (md%i)\n", + pr_err("cannot open (md%i)\n", mdstat->devnum); ret_val = 1; goto Grow_continue_command_exit; @@ -4105,7 +4081,7 @@ int Grow_continue_command(char *devname, int fd, if (mdmon_running(container_dev)) st->update_tail = &st->updates; else { - fprintf(stderr, Name ": No mdmon found. " + pr_err("No mdmon found. " "Grow cannot continue.\n"); ret_val = 1; goto Grow_continue_command_exit; diff --git a/Incremental.c b/Incremental.c index a61f4533..a94d5fa5 100644 --- a/Incremental.c +++ b/Incremental.c @@ -109,20 +109,20 @@ int Incremental(char *devname, int verbose, int runstop, if (stat(devname, &stb) < 0) { if (verbose >= 0) - fprintf(stderr, Name ": stat failed for %s: %s.\n", + pr_err("stat failed for %s: %s.\n", devname, strerror(errno)); return rv; } if ((stb.st_mode & S_IFMT) != S_IFBLK) { if (verbose >= 0) - fprintf(stderr, Name ": %s is not a block device.\n", + pr_err("%s is not a block device.\n", devname); return rv; } dfd = dev_open(devname, O_RDONLY|O_EXCL); if (dfd < 0) { if (verbose >= 0) - fprintf(stderr, Name ": cannot open %s: %s.\n", + pr_err("cannot open %s: %s.\n", devname, strerror(errno)); return rv; } @@ -136,8 +136,8 @@ int Incremental(char *devname, int verbose, int runstop, close(dfd); if (!rv && st->ss->container_content) { if (map_lock(&map)) - fprintf(stderr, Name ": failed to get " - "exclusive lock on mapfile\n"); + pr_err("failed to get " + "exclusive lock on mapfile\n"); rv = Incremental_container(st, devname, homehost, verbose, runstop, autof, freeze_reshape); @@ -145,7 +145,7 @@ int Incremental(char *devname, int verbose, int runstop, return rv; } - fprintf(stderr, Name ": %s is not part of an md array.\n", + pr_err("%s is not part of an md array.\n", devname); return rv; } @@ -154,9 +154,8 @@ int Incremental(char *devname, int verbose, int runstop, if (!conf_test_dev(devname)) { if (verbose >= 0) - fprintf(stderr, Name - ": %s not permitted by mdadm.conf.\n", - devname); + pr_err("%s not permitted by mdadm.conf.\n", + devname); goto out; } @@ -165,13 +164,13 @@ int Incremental(char *devname, int verbose, int runstop, if (fstat(dfd, &stb) < 0) { if (verbose >= 0) - fprintf(stderr, Name ": fstat failed for %s: %s.\n", + pr_err("fstat failed for %s: %s.\n", devname, strerror(errno)); goto out; } if ((stb.st_mode & S_IFMT) != S_IFBLK) { if (verbose >= 0) - fprintf(stderr, Name ": %s is not a block device.\n", + pr_err("%s is not a block device.\n", devname); goto out; } @@ -184,9 +183,8 @@ int Incremental(char *devname, int verbose, int runstop, if (st == NULL && (st = guess_super(dfd)) == NULL) { if (verbose >= 0) - fprintf(stderr, Name - ": no recognisable superblock on %s.\n", - devname); + pr_err("no recognisable superblock on %s.\n", + devname); rv = try_spare(devname, &dfd, policy, have_target ? &target_array : NULL, st, verbose); @@ -195,7 +193,7 @@ int Incremental(char *devname, int verbose, int runstop, if (st->ss->compare_super == NULL || st->ss->load_super(st, dfd, NULL)) { if (verbose >= 0) - fprintf(stderr, Name ": no RAID superblock on %s.\n", + pr_err("no RAID superblock on %s.\n", devname); rv = try_spare(devname, &dfd, policy, have_target ? &target_array : NULL, @@ -215,7 +213,7 @@ int Incremental(char *devname, int verbose, int runstop, if (match && match->devname && strcasecmp(match->devname, "") == 0) { if (verbose >= 0) - fprintf(stderr, Name ": array containing %s is explicitly" + pr_err("array containing %s is explicitly" " ignored by mdadm.conf\n", devname); goto out; @@ -238,10 +236,9 @@ int Incremental(char *devname, int verbose, int runstop, if (!match && !conf_test_metadata(st->ss->name, policy, (trustworthy == LOCAL))) { if (verbose >= 1) - fprintf(stderr, Name - ": %s has metadata type %s for which " - "auto-assembly is disabled\n", - devname, st->ss->name); + pr_err("%s has metadata type %s for which " + "auto-assembly is disabled\n", + devname, st->ss->name); goto out; } if (trustworthy == LOCAL_ANY) @@ -277,7 +274,7 @@ int Incremental(char *devname, int verbose, int runstop, /* 4/ Check if array exists. */ if (map_lock(&map)) - fprintf(stderr, Name ": failed to get exclusive lock on " + pr_err("failed to get exclusive lock on " "mapfile\n"); mp = map_by_uuid(&map, info.uuid); if (mp) @@ -297,7 +294,7 @@ int Incremental(char *devname, int verbose, int runstop, sysfs_init(&info, mdfd, 0); if (set_array_info(mdfd, st, &info) != 0) { - fprintf(stderr, Name ": failed to set array info for %s: %s\n", + pr_err("failed to set array info for %s: %s\n", chosen_name, strerror(errno)); rv = 2; goto out_unlock; @@ -307,7 +304,7 @@ int Incremental(char *devname, int verbose, int runstop, dinfo.disk.major = major(stb.st_rdev); dinfo.disk.minor = minor(stb.st_rdev); if (add_disk(mdfd, st, &info, &dinfo) != 0) { - fprintf(stderr, Name ": failed to add %s to %s: %s.\n", + pr_err("failed to add %s to %s: %s.\n", devname, chosen_name, strerror(errno)); ioctl(mdfd, STOP_ARRAY, 0); rv = 2; @@ -322,9 +319,8 @@ int Incremental(char *devname, int verbose, int runstop, * So reject it. */ ioctl(mdfd, STOP_ARRAY, NULL); - fprintf(stderr, Name - ": You have an old buggy kernel which cannot support\n" - " --incremental reliably. Aborting.\n"); + pr_err("You have an old buggy kernel which cannot support\n" + " --incremental reliably. Aborting.\n"); rv = 2; goto out_unlock; } @@ -369,9 +365,8 @@ int Incremental(char *devname, int verbose, int runstop, act_re_add) && runstop < 1) { if (ioctl(mdfd, GET_ARRAY_INFO, &ainf) == 0) { - fprintf(stderr, Name - ": not adding %s to active array (without --run) %s\n", - devname, chosen_name); + pr_err("not adding %s to active array (without --run) %s\n", + devname, chosen_name); rv = 2; goto out_unlock; } @@ -385,18 +380,16 @@ int Incremental(char *devname, int verbose, int runstop, sra->devs->disk.minor); dfd2 = dev_open(dn, O_RDONLY); if (dfd2 < 0) { - fprintf(stderr, Name - ": unable to open %s\n", devname); + pr_err("unable to open %s\n", devname); rv = 2; goto out_unlock; } st2 = dup_super(st); if (st2->ss->load_super(st2, dfd2, NULL) || st->ss->compare_super(st, st2) != 0) { - fprintf(stderr, Name - ": metadata mismatch between %s and " - "chosen array %s\n", - devname, chosen_name); + pr_err("metadata mismatch between %s and " + "chosen array %s\n", + devname, chosen_name); close(dfd2); rv = 2; goto out_unlock; @@ -407,9 +400,8 @@ int Incremental(char *devname, int verbose, int runstop, if (info.array.level != info2.array.level || memcmp(info.uuid, info2.uuid, 16) != 0 || info.array.raid_disks != info2.array.raid_disks) { - fprintf(stderr, Name - ": unexpected difference between %s and %s.\n", - chosen_name, devname); + pr_err("unexpected difference between %s and %s.\n", + chosen_name, devname); rv = 2; goto out_unlock; } @@ -429,7 +421,7 @@ int Incremental(char *devname, int verbose, int runstop, err = add_disk(mdfd, st, sra, &info); } if (err < 0) { - fprintf(stderr, Name ": failed to add %s to %s: %s.\n", + pr_err("failed to add %s to %s: %s.\n", devname, chosen_name, strerror(errno)); rv = 2; goto out_unlock; @@ -447,10 +439,9 @@ int Incremental(char *devname, int verbose, int runstop, /* Try to assemble within the container */ sysfs_uevent(sra, "change"); if (verbose >= 0) - fprintf(stderr, Name - ": container %s now has %d device%s\n", - chosen_name, info.array.working_disks, - info.array.working_disks==1?"":"s"); + pr_err("container %s now has %d device%s\n", + chosen_name, info.array.working_disks, + info.array.working_disks==1?"":"s"); wait_for(chosen_name, mdfd); if (st->ss->external) devnum = fd2devnum(mdfd); @@ -487,9 +478,8 @@ int Incremental(char *devname, int verbose, int runstop, info.array.layout, info.array.state & 1, avail) == 0) { if (verbose >= 0) - fprintf(stderr, Name - ": %s attached to %s, not enough to start (%d).\n", - devname, chosen_name, active_disks); + pr_err("%s attached to %s, not enough to start (%d).\n", + devname, chosen_name, active_disks); rv = 0; goto out_unlock; } @@ -502,9 +492,8 @@ int Incremental(char *devname, int verbose, int runstop, if (ioctl(mdfd, GET_ARRAY_INFO, &ainf) == 0) { if (verbose >= 0) - fprintf(stderr, Name - ": %s attached to %s which is already active.\n", - devname, chosen_name); + pr_err("%s attached to %s which is already active.\n", + devname, chosen_name); rv = 0; goto out_unlock; } @@ -516,16 +505,14 @@ int Incremental(char *devname, int verbose, int runstop, if (match && match->bitmap_file) { int bmfd = open(match->bitmap_file, O_RDWR); if (bmfd < 0) { - fprintf(stderr, Name - ": Could not open bitmap file %s.\n", - match->bitmap_file); + pr_err("Could not open bitmap file %s.\n", + match->bitmap_file); goto out; } if (ioctl(mdfd, SET_BITMAP_FILE, bmfd) != 0) { close(bmfd); - fprintf(stderr, Name - ": Failed to set bitmapfile for %s.\n", - chosen_name); + pr_err("Failed to set bitmapfile for %s.\n", + chosen_name); goto out; } close(bmfd); @@ -545,9 +532,8 @@ int Incremental(char *devname, int verbose, int runstop, "array_state", "read-auto"); if (rv == 0) { if (verbose >= 0) - fprintf(stderr, Name - ": %s attached to %s, which has been started.\n", - devname, chosen_name); + pr_err("%s attached to %s, which has been started.\n", + devname, chosen_name); rv = 0; wait_for(chosen_name, mdfd); /* We just started the array, so some devices @@ -559,21 +545,18 @@ int Incremental(char *devname, int verbose, int runstop, for (dsk = sra->devs; dsk ; dsk = dsk->next) { if (disk_action_allows(dsk, st->ss->name, act_re_add) && add_disk(mdfd, st, sra, dsk) == 0) - fprintf(stderr, Name - ": %s re-added to %s\n", - dsk->sys_name, chosen_name); + pr_err("%s re-added to %s\n", + dsk->sys_name, chosen_name); } } else { - fprintf(stderr, Name - ": %s attached to %s, but failed to start: %s.\n", - devname, chosen_name, strerror(errno)); + pr_err("%s attached to %s, but failed to start: %s.\n", + devname, chosen_name, strerror(errno)); rv = 1; } } else { if (verbose >= 0) - fprintf(stderr, Name - ": %s attached to %s, not enough to start safely.\n", - devname, chosen_name); + pr_err("%s attached to %s, not enough to start safely.\n", + devname, chosen_name); rv = 0; } out: @@ -630,9 +613,8 @@ static void find_reject(int mdfd, struct supertype *st, struct mdinfo *sra, sysfs_set_str(sra, d, "slot", "none"); if (sysfs_set_str(sra, d, "state", "remove") == 0) if (verbose >= 0) - fprintf(stderr, Name - ": removing old device %s from %s\n", - d->sys_name+4, array_name); + pr_err("removing old device %s from %s\n", + d->sys_name+4, array_name); } } @@ -677,7 +659,7 @@ static int count_active(struct supertype *st, struct mdinfo *sra, raid_disks = info.array.raid_disks; avail = calloc(raid_disks, 1); if (!avail) { - fprintf(stderr, Name ": out of memory.\n"); + pr_err("out of memory.\n"); exit(1); } *availp = avail; @@ -811,7 +793,7 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol, */ if (map_lock(&map)) { - fprintf(stderr, Name ": failed to get exclusive lock on " + pr_err("failed to get exclusive lock on " "mapfile\n"); return 1; } @@ -830,7 +812,7 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol, (st->minor_version >= 0 && st->minor_version != st2->minor_version)) { if (verbose > 1) - fprintf(stderr, Name ": not adding %s to %s as metadata type doesn't match\n", + pr_err("not adding %s to %s as metadata type doesn't match\n", devname, mp->path); free(st2); continue; @@ -858,7 +840,7 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol, sra->text_version); if (!st2) { if (verbose > 1) - fprintf(stderr, Name ": not adding %s to %s" + pr_err("not adding %s to %s" " as metadata not recognised.\n", devname, mp->path); goto next; @@ -901,7 +883,7 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol, || (sra->component_size == 0 && devsize < component_size)) { if (verbose > 1) - fprintf(stderr, Name ": not adding %s to %s as it is too small\n", + pr_err("not adding %s to %s as it is too small\n", devname, mp->path); goto next; } @@ -937,7 +919,7 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol, if (domain_test(dl, pol, st2->ss->name) != 1) { /* domain test fails */ if (verbose > 1) - fprintf(stderr, Name ": not adding %s to %s as" + pr_err("not adding %s to %s as" " it is not in a compatible domain\n", devname, mp->path); @@ -982,10 +964,10 @@ static int array_try_spare(char *devname, int *dfdp, struct dev_policy *pol, } if (verbose > 0) { if (rv == 0) - fprintf(stderr, Name ": added %s as spare for %s\n", + pr_err("added %s as spare for %s\n", devname, chosen->sys_name); else - fprintf(stderr, Name ": failed to add %s as spare for %s\n", + pr_err("failed to add %s as spare for %s\n", devname, chosen->sys_name); } sysfs_free(chosen); @@ -1211,7 +1193,7 @@ static int try_spare(char *devname, int *dfdp, struct dev_policy *pol, !policy_action_allows(pol, st?st->ss->name:NULL, act_spare_same_slot)) { if (verbose > 1) - fprintf(stderr, Name ": %s is not bare, so not " + pr_err("%s is not bare, so not " "considering as a spare\n", devname); return 1; @@ -1305,13 +1287,11 @@ int IncrementalScan(int verbose) } if (verbose >= 0) { if (added == 0) - fprintf(stderr, Name - ": Added bitmap %s to %s\n", - mddev->bitmap_file, me->path); + pr_err("Added bitmap %s to %s\n", + mddev->bitmap_file, me->path); else if (errno != EEXIST) - fprintf(stderr, Name - ": Failed to add bitmap to %s: %s\n", - me->path, strerror(errno)); + pr_err("Failed to add bitmap to %s: %s\n", + me->path, strerror(errno)); } } sra = sysfs_read(mdfd, 0, 0); @@ -1319,14 +1299,12 @@ int IncrementalScan(int verbose) if (sysfs_set_str(sra, NULL, "array_state", "read-auto") == 0) { if (verbose >= 0) - fprintf(stderr, Name - ": started array %s\n", - me->path ?: devnum2devname(me->devnum)); + pr_err("started array %s\n", + me->path ?: devnum2devname(me->devnum)); } else { - fprintf(stderr, Name - ": failed to start array %s: %s\n", - me->path ?: devnum2devname(me->devnum), - strerror(errno)); + pr_err("failed to start array %s: %s\n", + me->path ?: devnum2devname(me->devnum), + strerror(errno)); rv = 1; } sysfs_free(sra); @@ -1389,7 +1367,7 @@ static int Incremental_container(struct supertype *st, char *devname, /* pass */; else { if (verbose) - fprintf(stderr, Name ": not enough devices to start the container\n"); + pr_err("not enough devices to start the container\n"); return 0; } @@ -1420,7 +1398,7 @@ static int Incremental_container(struct supertype *st, char *devname, ra_all++; /* do not activate arrays blocked by metadata handler */ if (ra->array.state & (1 << MD_SB_BLOCK_VOLUME)) { - fprintf(stderr, Name ": Cannot activate array %s in %s.\n", + pr_err("Cannot activate array %s in %s.\n", ra->text_version, devname); ra_blocked++; continue; @@ -1468,7 +1446,7 @@ static int Incremental_container(struct supertype *st, char *devname, /* we have a match */ match = array_list; if (verbose>0) - fprintf(stderr, Name ": match found for member %s\n", + pr_err("match found for member %s\n", array_list->member); break; } @@ -1476,9 +1454,9 @@ static int Incremental_container(struct supertype *st, char *devname, if (match && match->devname && strcasecmp(match->devname, "") == 0) { if (verbose > 0) - fprintf(stderr, Name ": array %s/%s is " - "explicitly ignored by mdadm.conf\n", - match->container, match->member); + pr_err("array %s/%s is " + "explicitly ignored by mdadm.conf\n", + match->container, match->member); return 2; } if (match) @@ -1492,7 +1470,7 @@ static int Incremental_container(struct supertype *st, char *devname, } if (mdfd < 0) { - fprintf(stderr, Name ": failed to open %s: %s.\n", + pr_err("failed to open %s: %s.\n", chosen_name, strerror(errno)); return 2; } @@ -1544,9 +1522,8 @@ static int Incremental_container(struct supertype *st, char *devname, disks = disks->next; } if (count) - fprintf(stderr, Name - ": Added %d spare%s to %s\n", - count, count>1?"s":"", devname); + pr_err("Added %d spare%s to %s\n", + count, count>1?"s":"", devname); } sysfs_free(sinfo); } else @@ -1579,19 +1556,19 @@ int IncrementalRemove(char *devname, char *id_path, int verbose) "port\n"); if (strchr(devname, '/')) { - fprintf(stderr, Name ": incremental removal requires a " + pr_err("incremental removal requires a " "kernel device name, not a file: %s\n", devname); return 1; } ent = mdstat_by_component(devname); if (!ent) { - fprintf(stderr, Name ": %s does not appear to be a component " + pr_err("%s does not appear to be a component " "of any array\n", devname); return 1; } mdfd = open_dev(ent->devnum); if (mdfd < 0) { - fprintf(stderr, Name ": Cannot open array %s!!\n", ent->dev); + pr_err("Cannot open array %s!!\n", ent->dev); free_mdstat(ent); return 1; } diff --git a/Kill.c b/Kill.c index bac48440..a271b65c 100644 --- a/Kill.c +++ b/Kill.c @@ -47,7 +47,7 @@ int Kill(char *dev, struct supertype *st, int force, int quiet, int noexcl) fd = open(dev, O_RDWR|(noexcl ? 0 : O_EXCL)); if (fd < 0) { if (!quiet) - fprintf(stderr, Name ": Couldn't open %s for write - not zeroing\n", + pr_err("Couldn't open %s for write - not zeroing\n", dev); return 2; } @@ -55,7 +55,7 @@ int Kill(char *dev, struct supertype *st, int force, int quiet, int noexcl) st = guess_super(fd); if (st == NULL || st->ss->init_super == NULL) { if (!quiet) - fprintf(stderr, Name ": Unrecognised md component device - %s\n", dev); + pr_err("Unrecognised md component device - %s\n", dev); close(fd); return 2; } @@ -66,12 +66,12 @@ int Kill(char *dev, struct supertype *st, int force, int quiet, int noexcl) st->ss->init_super(st, NULL, 0, "", NULL, NULL); if (st->ss->store_super(st, fd)) { if (!quiet) - fprintf(stderr, Name ": Could not zero superblock on %s\n", + pr_err("Could not zero superblock on %s\n", dev); rv = 1; } else if (rv) { if (!quiet) - fprintf(stderr, Name ": superblock zeroed anyway\n"); + pr_err("superblock zeroed anyway\n"); rv = 0; } } @@ -101,17 +101,15 @@ int Kill_subarray(char *dev, char *subarray, int quiet) if (!st->ss->kill_subarray) { if (!quiet) - fprintf(stderr, - Name ": Operation not supported for %s metadata\n", - st->ss->name); + pr_err("Operation not supported for %s metadata\n", + st->ss->name); goto free_super; } if (is_subarray_active(subarray, st->devname)) { if (!quiet) - fprintf(stderr, - Name ": Subarray-%s still active, aborting\n", - subarray); + pr_err("Subarray-%s still active, aborting\n", + subarray); goto free_super; } @@ -122,9 +120,8 @@ int Kill_subarray(char *dev, char *subarray, int quiet) rv = st->ss->kill_subarray(st); if (rv) { if (!quiet) - fprintf(stderr, - Name ": Failed to delete subarray-%s from %s\n", - subarray, dev); + pr_err("Failed to delete subarray-%s from %s\n", + subarray, dev); goto free_super; } @@ -135,9 +132,8 @@ int Kill_subarray(char *dev, char *subarray, int quiet) st->ss->sync_metadata(st); if (!quiet) - fprintf(stderr, - Name ": Deleted subarray-%s from %s, UUIDs may have changed\n", - subarray, dev); + pr_err("Deleted subarray-%s from %s, UUIDs may have changed\n", + subarray, dev); rv = 0; diff --git a/Manage.c b/Manage.c index 95aa2704..a7d6a1e8 100644 --- a/Manage.c +++ b/Manage.c @@ -47,7 +47,7 @@ int Manage_ro(char *devname, int fd, int readonly) int rv = 0; if (md_get_version(fd) < 9000) { - fprintf(stderr, Name ": need md driver version 0.90.0 or later\n"); + pr_err("need md driver version 0.90.0 or later\n"); return 1; } #ifndef MDASSEMBLE @@ -71,7 +71,7 @@ int Manage_ro(char *devname, int fd, int readonly) rv = sysfs_set_str(mdi, NULL, "array_state", "readonly"); if (rv < 0) { - fprintf(stderr, Name ": failed to set readonly for %s: %s\n", + pr_err("failed to set readonly for %s: %s\n", devname, strerror(errno)); vers[9] = mdi->text_version[0]; @@ -96,7 +96,7 @@ int Manage_ro(char *devname, int fd, int readonly) } #endif if (ioctl(fd, GET_ARRAY_INFO, &array)) { - fprintf(stderr, Name ": %s does not appear to be active.\n", + pr_err("%s does not appear to be active.\n", devname); rv = 1; goto out; @@ -104,14 +104,14 @@ int Manage_ro(char *devname, int fd, int readonly) if (readonly>0) { if (ioctl(fd, STOP_ARRAY_RO, NULL)) { - fprintf(stderr, Name ": failed to set readonly for %s: %s\n", + pr_err("failed to set readonly for %s: %s\n", devname, strerror(errno)); rv = 1; goto out; } } else if (readonly < 0) { if (ioctl(fd, RESTART_ARRAY_RW, NULL)) { - fprintf(stderr, Name ": failed to set writable for %s: %s\n", + pr_err("failed to set writable for %s: %s\n", devname, strerror(errno)); rv = 1; goto out; @@ -187,33 +187,32 @@ int Manage_runstop(char *devname, int fd, int runstop, int quiet) if (runstop == -1 && md_get_version(fd) < 9000) { if (ioctl(fd, STOP_MD, 0)) { - if (quiet == 0) fprintf(stderr, - Name ": stopping device %s " - "failed: %s\n", - devname, strerror(errno)); + pr_err("stopping device %s " + "failed: %s\n", + devname, strerror(errno)); return 1; } } if (md_get_version(fd) < 9000) { - fprintf(stderr, Name ": need md driver version 0.90.0 or later\n"); + pr_err("need md driver version 0.90.0 or later\n"); return 1; } /* if (ioctl(fd, GET_ARRAY_INFO, &array)) { - fprintf(stderr, Name ": %s does not appear to be active.\n", + pr_err("%s does not appear to be active.\n", devname); return 1; } */ if (runstop>0) { if (ioctl(fd, RUN_ARRAY, ¶m)) { - fprintf(stderr, Name ": failed to run array %s: %s\n", + pr_err("failed to run array %s: %s\n", devname, strerror(errno)); return 1; } if (quiet <= 0) - fprintf(stderr, Name ": started %s\n", devname); + pr_err("started %s\n", devname); } else if (runstop < 0){ struct map_ent *map = NULL; struct stat stb; @@ -233,12 +232,11 @@ int Manage_runstop(char *devname, int fd, int runstop, int quiet) if (fd < 0 || fd2devnum(fd) != devnum) { if (fd >= 0) close(fd); - fprintf(stderr, - Name ": Cannot get exclusive access to %s:" - "Perhaps a running " - "process, mounted filesystem " - "or active volume group?\n", - devname); + pr_err("Cannot get exclusive access to %s:" + "Perhaps a running " + "process, mounted filesystem " + "or active volume group?\n", + devname); return 1; } mdi = sysfs_read(fd, -1, GET_LEVEL|GET_VERSION); @@ -259,9 +257,8 @@ int Manage_runstop(char *devname, int fd, int runstop, int quiet) count--; } if (err && !quiet) { - fprintf(stderr, Name - ": failed to stop array %s: %s\n", - devname, strerror(errno)); + pr_err("failed to stop array %s: %s\n", + devname, strerror(errno)); rv = 1; goto out; } @@ -271,10 +268,9 @@ int Manage_runstop(char *devname, int fd, int runstop, int quiet) fd = open_dev_excl(devnum); if (fd < 0) { - fprintf(stderr, Name - ": failed to completely stop %s" - ": Device is busy\n", - devname); + pr_err("failed to completely stop %s" + ": Device is busy\n", + devname); rv = 1; goto out; } @@ -299,10 +295,9 @@ int Manage_runstop(char *devname, int fd, int runstop, int quiet) is_subarray(m->metadata_version+9) && devname2devnum(m->metadata_version+10) == devnum) { if (!quiet) - fprintf(stderr, Name - ": Cannot stop container %s: " - "member %s still active\n", - devname, m->dev); + pr_err("Cannot stop container %s: " + "member %s still active\n", + devname, m->dev); free_mdstat(mds); rv = 1; goto out; @@ -322,9 +317,8 @@ int Manage_runstop(char *devname, int fd, int runstop, int quiet) } if (fd >= 0 && err) { if (quiet == 0) { - fprintf(stderr, Name - ": failed to stop array %s: %s\n", - devname, strerror(errno)); + pr_err("failed to stop array %s: %s\n", + devname, strerror(errno)); if (errno == EBUSY) fprintf(stderr, "Perhaps a running " "process, mounted filesystem " @@ -352,7 +346,7 @@ int Manage_runstop(char *devname, int fd, int runstop, int quiet) if (quiet <= 0) - fprintf(stderr, Name ": stopped %s\n", devname); + pr_err("stopped %s\n", devname); map_lock(&map); map_remove(&map, devnum); map_unlock(&map); @@ -367,7 +361,7 @@ int Manage_resize(char *devname, int fd, long long size, int raid_disks) { mdu_array_info_t info; if (ioctl(fd, GET_ARRAY_INFO, &info) != 0) { - fprintf(stderr, Name ": Cannot get array information for %s: %s\n", + pr_err("Cannot get array information for %s: %s\n", devname, strerror(errno)); return 1; } @@ -376,7 +370,7 @@ int Manage_resize(char *devname, int fd, long long size, int raid_disks) if (raid_disks > 0) info.raid_disks = raid_disks; if (ioctl(fd, SET_ARRAY_INFO, &info) != 0) { - fprintf(stderr, Name ": Cannot set device size/shape for %s: %s\n", + pr_err("Cannot set device size/shape for %s: %s\n", devname, strerror(errno)); return 1; } @@ -420,7 +414,7 @@ int Manage_subdevs(char *devname, int fd, int frozen = 0; if (ioctl(fd, GET_ARRAY_INFO, &array)) { - fprintf(stderr, Name ": cannot get array info for %s\n", + pr_err("cannot get array info for %s\n", devname); goto abort; } @@ -436,7 +430,7 @@ int Manage_subdevs(char *devname, int fd, tst = super_by_fd(fd, &subarray); if (!tst) { - fprintf(stderr, Name ": unsupport array - version %d.%d\n", + pr_err("unsupport array - version %d.%d\n", array.major_version, array.minor_version); goto abort; } @@ -457,7 +451,7 @@ int Manage_subdevs(char *devname, int fd, strcmp(dv->devname, "faulty")==0) { int remaining_disks = array.nr_disks; if (dv->disposition != 'r') { - fprintf(stderr, Name ": %s only meaningful " + pr_err("%s only meaningful " "with -r, not -%c\n", dv->devname, dv->disposition); goto abort; @@ -490,7 +484,7 @@ int Manage_subdevs(char *devname, int fd, } else if (strcmp(dv->devname, "detached") == 0) { int remaining_disks = array.nr_disks; if (dv->disposition != 'r' && dv->disposition != 'f') { - fprintf(stderr, Name ": %s only meaningful " + pr_err("%s only meaningful " "with -r of -f, not -%c\n", dv->devname, dv->disposition); goto abort; @@ -531,14 +525,14 @@ int Manage_subdevs(char *devname, int fd, continue; } else if (strcmp(dv->devname, "missing") == 0) { if (dv->disposition != 'a' || dv->re_add == 0) { - fprintf(stderr, Name ": 'missing' only meaningful " + pr_err("'missing' only meaningful " "with --re-add\n"); goto abort; } if (add_devlist == NULL) add_devlist = conf_get_devs(); if (add_devlist == NULL) { - fprintf(stderr, Name ": no devices to scan for missing members."); + pr_err("no devices to scan for missing members."); continue; } add_dev = add_devlist->devname; @@ -554,7 +548,7 @@ int Manage_subdevs(char *devname, int fd, int found = 0; char dname[55]; if (dv->disposition != 'r' && dv->disposition != 'f') { - fprintf(stderr, Name ": %s only meaningful " + pr_err("%s only meaningful " "with -r or -f, not -%c\n", dv->devname, dv->disposition); goto abort; @@ -576,7 +570,7 @@ int Manage_subdevs(char *devname, int fd, if (!found) { sysfd = sysfs_open(fd2devnum(fd), dname, "state"); if (sysfd < 0) { - fprintf(stderr, Name ": %s does not appear " + pr_err("%s does not appear " "to be a component of %s\n", dv->devname, devname); goto abort; @@ -594,7 +588,7 @@ int Manage_subdevs(char *devname, int fd, ; else { if (tfd < 0 || fstat(tfd, &stb) != 0) { - fprintf(stderr, Name ": cannot find %s: %s\n", + pr_err("cannot find %s: %s\n", dv->devname, strerror(errno)); if (tfd >= 0) close(tfd); @@ -604,7 +598,7 @@ int Manage_subdevs(char *devname, int fd, tfd = -1; } if ((stb.st_mode & S_IFMT) != S_IFBLK) { - fprintf(stderr, Name ": %s is not a " + pr_err("%s is not a " "block device.\n", dv->devname); goto abort; @@ -612,13 +606,13 @@ int Manage_subdevs(char *devname, int fd, } switch(dv->disposition){ default: - fprintf(stderr, Name ": internal error - devmode[%s]=%d\n", + pr_err("internal error - devmode[%s]=%d\n", dv->devname, dv->disposition); goto abort; case 'a': /* add the device */ if (subarray) { - fprintf(stderr, Name ": Cannot add disks to a" + pr_err("Cannot add disks to a" " \'member\' array, perform this" " operation on the parent container\n"); goto abort; @@ -628,7 +622,7 @@ int Manage_subdevs(char *devname, int fd, if (tfd < 0 && add_dev != dv->devname) continue; if (tfd < 0) { - fprintf(stderr, Name ": Cannot open %s: %s\n", + pr_err("Cannot open %s: %s\n", dv->devname, strerror(errno)); goto abort; } @@ -662,22 +656,20 @@ int Manage_subdevs(char *devname, int fd, array.raid_disks, NULL, ldsize >> 9, NULL, NULL, 0) == 0) { if (!force) { - fprintf(stderr, Name - ": %s is larger than %s can " - "effectively use.\n" - " Add --force is you " - "really want to add this device.\n", - add_dev, devname); + pr_err("%s is larger than %s can " + "effectively use.\n" + " Add --force is you " + "really want to add this device.\n", + add_dev, devname); st->ss->free_super(st); close(tfd); goto abort; } - fprintf(stderr, Name - ": %s is larger than %s can " - "effectively use.\n" - " Adding anyway as --force " - "was given.\n", - add_dev, devname); + pr_err("%s is larger than %s can " + "effectively use.\n" + " Adding anyway as --force " + "was given.\n", + add_dev, devname); } if (!tst->ss->external && array.major_version == 0 && @@ -688,12 +680,12 @@ int Manage_subdevs(char *devname, int fd, if (ioctl(fd, HOT_ADD_DISK, (unsigned long)stb.st_rdev)==0) { if (verbose >= 0) - fprintf(stderr, Name ": hot added %s\n", + pr_err("hot added %s\n", add_dev); continue; } - fprintf(stderr, Name ": hot add failed for %s: %s\n", + pr_err("hot add failed for %s: %s\n", add_dev, strerror(errno)); goto abort; } @@ -741,7 +733,7 @@ int Manage_subdevs(char *devname, int fd, } else if (!tst->sb) { close(tfd); st->ss->free_super(st); - fprintf(stderr, Name ": cannot load array metadata from %s\n", devname); + pr_err("cannot load array metadata from %s\n", devname); goto abort; } @@ -753,7 +745,7 @@ int Manage_subdevs(char *devname, int fd, st->ss->free_super(st); if (add_dev != dv->devname) continue; - fprintf(stderr, Name ": %s not large enough to join array\n", + pr_err("%s not large enough to join array\n", dv->devname); goto abort; } @@ -805,7 +797,7 @@ int Manage_subdevs(char *devname, int fd, int rv = -1; tfd = dev_open(dv->devname, O_RDWR); if (tfd < 0) { - fprintf(stderr, Name ": failed to open %s for" + pr_err("failed to open %s for" " superblock update during re-add\n", dv->devname); st->ss->free_super(st); goto abort; @@ -828,8 +820,8 @@ int Manage_subdevs(char *devname, int fd, close(tfd); tfd = -1; if (rv != 0) { - fprintf(stderr, Name ": failed to update" - " superblock during re-add\n"); + pr_err("failed to update" + " superblock during re-add\n"); st->ss->free_super(st); goto abort; } @@ -838,13 +830,13 @@ int Manage_subdevs(char *devname, int fd, errno = 0; if (ioctl(fd, ADD_NEW_DISK, &disc) == 0) { if (verbose >= 0) - fprintf(stderr, Name ": re-added %s\n", add_dev); + pr_err("re-added %s\n", add_dev); count++; st->ss->free_super(st); continue; } if (errno == ENOMEM || errno == EROFS) { - fprintf(stderr, Name ": add new device failed for %s: %s\n", + pr_err("add new device failed for %s: %s\n", add_dev, strerror(errno)); st->ss->free_super(st); if (add_dev != dv->devname) @@ -857,9 +849,8 @@ int Manage_subdevs(char *devname, int fd, } if (add_dev != dv->devname) { if (verbose > 0) - fprintf(stderr, Name - ": --re-add for %s to %s is not possible\n", - add_dev, devname); + pr_err("--re-add for %s to %s is not possible\n", + add_dev, devname); if (tfd >= 0) { close(tfd); tfd = -1; @@ -869,9 +860,8 @@ int Manage_subdevs(char *devname, int fd, if (dv->re_add) { if (tfd >= 0) close(tfd); - fprintf(stderr, Name - ": --re-add for %s to %s is not possible\n", - dv->devname, devname); + pr_err("--re-add for %s to %s is not possible\n", + dv->devname, devname); goto abort; } if (array.active_disks < array.raid_disks) { @@ -895,9 +885,9 @@ int Manage_subdevs(char *devname, int fd, } else array_failed = 0; if (array_failed) { - fprintf(stderr, Name ": %s has failed so using --add cannot work and might destroy\n", + pr_err("%s has failed so using --add cannot work and might destroy\n", devname); - fprintf(stderr, Name ": data on %s. You should stop the array and re-assemble it.\n", + pr_err("data on %s. You should stop the array and re-assemble it.\n", dv->devname); if (tfd >= 0) close(tfd); @@ -908,7 +898,7 @@ int Manage_subdevs(char *devname, int fd, * is at least array.size big. */ if (ldsize/512 < array_size) { - fprintf(stderr, Name ": %s not large enough to join array\n", + pr_err("%s not large enough to join array\n", dv->devname); if (tfd >= 0) close(tfd); @@ -996,9 +986,9 @@ int Manage_subdevs(char *devname, int fd, container_fd = open_dev_excl(devnum); if (container_fd < 0) { - fprintf(stderr, Name ": add failed for %s:" - " could not get exclusive access to container\n", - dv->devname); + pr_err("add failed for %s:" + " could not get exclusive access to container\n", + dv->devname); tst->ss->free_super(tst); goto abort; } @@ -1019,7 +1009,7 @@ int Manage_subdevs(char *devname, int fd, sra = sysfs_read(container_fd, -1, 0); if (!sra) { - fprintf(stderr, Name ": add failed for %s: sysfs_read failed\n", + pr_err("add failed for %s: sysfs_read failed\n", dv->devname); close(container_fd); tst->ss->free_super(tst); @@ -1035,7 +1025,7 @@ int Manage_subdevs(char *devname, int fd, * would block add_disk */ tst->ss->free_super(tst); if (sysfs_add_disk(sra, &new_mdi, 0) != 0) { - fprintf(stderr, Name ": add new device to external metadata" + pr_err("add new device to external metadata" " failed for %s\n", dv->devname); close(container_fd); sysfs_free(sra); @@ -1047,19 +1037,19 @@ int Manage_subdevs(char *devname, int fd, } else { tst->ss->free_super(tst); if (ioctl(fd, ADD_NEW_DISK, &disc)) { - fprintf(stderr, Name ": add new device failed for %s as %d: %s\n", + pr_err("add new device failed for %s as %d: %s\n", dv->devname, j, strerror(errno)); goto abort; } } if (verbose >= 0) - fprintf(stderr, Name ": added %s\n", dv->devname); + pr_err("added %s\n", dv->devname); break; case 'r': /* hot remove */ if (subarray) { - fprintf(stderr, Name ": Cannot remove disks from a" + pr_err("Cannot remove disks from a" " \'member\' array, perform this" " operation on the parent container\n"); if (sysfd >= 0) @@ -1079,9 +1069,8 @@ int Manage_subdevs(char *devname, int fd, int dnum = fd2devnum(fd); lfd = open_dev_excl(dnum); if (lfd < 0) { - fprintf(stderr, Name - ": Cannot get exclusive access " - " to container - odd\n"); + pr_err("Cannot get exclusive access " + " to container - odd\n"); if (sysfd >= 0) close(sysfd); goto abort; @@ -1095,11 +1084,10 @@ int Manage_subdevs(char *devname, int fd, sysfs_unique_holder(dnum, stb.st_rdev)) /* pass */; else { - fprintf(stderr, Name - ": %s is %s, cannot remove.\n", - dnprintable, - errno == EEXIST ? "still in use": - "not a member"); + pr_err("%s is %s, cannot remove.\n", + dnprintable, + errno == EEXIST ? "still in use": + "not a member"); close(lfd); goto abort; } @@ -1139,9 +1127,9 @@ int Manage_subdevs(char *devname, int fd, } } if (err) { - fprintf(stderr, Name ": hot remove failed " - "for %s: %s\n", dnprintable, - strerror(errno)); + pr_err("hot remove failed " + "for %s: %s\n", dnprintable, + strerror(errno)); if (lfd >= 0) close(lfd); goto abort; @@ -1156,7 +1144,7 @@ int Manage_subdevs(char *devname, int fd, char *name = devnum2devname(fd2devnum(fd)); if (!name) { - fprintf(stderr, Name ": unable to get container name\n"); + pr_err("unable to get container name\n"); goto abort; } @@ -1167,7 +1155,7 @@ int Manage_subdevs(char *devname, int fd, close(lfd); count++; if (verbose >= 0) - fprintf(stderr, Name ": hot removed %s from %s\n", + pr_err("hot removed %s from %s\n", dnprintable, devname); break; @@ -1176,7 +1164,7 @@ int Manage_subdevs(char *devname, int fd, if ((sysfd >= 0 && write(sysfd, "faulty", 6) != 6) || (sysfd < 0 && ioctl(fd, SET_DISK_FAULTY, (unsigned long) stb.st_rdev))) { - fprintf(stderr, Name ": set device faulty failed for %s: %s\n", + pr_err("set device faulty failed for %s: %s\n", dnprintable, strerror(errno)); if (sysfd >= 0) close(sysfd); @@ -1187,7 +1175,7 @@ int Manage_subdevs(char *devname, int fd, sysfd = -1; count++; if (verbose >= 0) - fprintf(stderr, Name ": set %s faulty in %s\n", + pr_err("set %s faulty in %s\n", dnprintable, devname); break; } @@ -1230,9 +1218,8 @@ int Update_subarray(char *dev, char *subarray, char *update, struct mddev_ident if (!st->ss->update_subarray) { if (!quiet) - fprintf(stderr, - Name ": Operation not supported for %s metadata\n", - st->ss->name); + pr_err("Operation not supported for %s metadata\n", + st->ss->name); goto free_super; } @@ -1243,7 +1230,7 @@ int Update_subarray(char *dev, char *subarray, char *update, struct mddev_ident if (rv) { if (!quiet) - fprintf(stderr, Name ": Failed to update %s of subarray-%s in %s\n", + pr_err("Failed to update %s of subarray-%s in %s\n", update, subarray, dev); } else if (st->update_tail) flush_metadata_updates(st); @@ -1251,9 +1238,8 @@ int Update_subarray(char *dev, char *subarray, char *update, struct mddev_ident st->ss->sync_metadata(st); if (rv == 0 && strcmp(update, "name") == 0 && !quiet) - fprintf(stderr, - Name ": Updated subarray-%s name from %s, UUIDs may have changed\n", - subarray, dev); + pr_err("Updated subarray-%s name from %s, UUIDs may have changed\n", + subarray, dev); free_super: st->ss->free_super(st); diff --git a/Monitor.c b/Monitor.c index 34b99d67..35a984f8 100644 --- a/Monitor.c +++ b/Monitor.c @@ -128,7 +128,7 @@ int Monitor(struct mddev_dev *devlist, if (!mailaddr) { mailaddr = conf_get_mailaddr(); if (mailaddr && ! scan) - fprintf(stderr, Name ": Monitor using email address \"%s\" from config file\n", + pr_err("Monitor using email address \"%s\" from config file\n", mailaddr); } mailfrom = conf_get_mailfrom(); @@ -136,11 +136,11 @@ int Monitor(struct mddev_dev *devlist, if (!alert_cmd) { alert_cmd = conf_get_program(); if (alert_cmd && ! scan) - fprintf(stderr, Name ": Monitor using program \"%s\" from config file\n", + pr_err("Monitor using program \"%s\" from config file\n", alert_cmd); } if (scan && !mailaddr && !alert_cmd && !dosyslog) { - fprintf(stderr, Name ": No mail address or alert command - not monitoring.\n"); + pr_err("No mail address or alert command - not monitoring.\n"); return 1; } info.alert_cmd = alert_cmd; @@ -301,13 +301,13 @@ static int check_one_sharer(int scan) rv = stat(dir, &buf); if (rv != -1) { if (scan) { - fprintf(stderr, Name ": Only one " + pr_err("Only one " "autorebuild process allowed" " in scan mode, aborting\n"); fclose(fp); return 1; } else { - fprintf(stderr, Name ": Warning: One" + pr_err("Warning: One" " autorebuild process already" " running.\n"); } @@ -317,12 +317,12 @@ static int check_one_sharer(int scan) if (scan) { if (mkdir(MDMON_DIR, S_IRWXU) < 0 && errno != EEXIST) { - fprintf(stderr, Name ": Can't create " + pr_err("Can't create " "autorebuild.pid file\n"); } else { fp = fopen(path, "w"); if (!fp) - fprintf(stderr, Name ": Cannot create" + pr_err("Cannot create" " autorebuild.pid" "file\n"); else { @@ -962,7 +962,7 @@ int Wait(char *dev) int rv = 1; if (stat(dev, &stb) != 0) { - fprintf(stderr, Name ": Cannot find %s: %s\n", dev, + pr_err("Cannot find %s: %s\n", dev, strerror(errno)); return 2; } @@ -1008,7 +1008,7 @@ int WaitClean(char *dev, int sock, int verbose) fd = open(dev, O_RDONLY); if (fd < 0) { if (verbose) - fprintf(stderr, Name ": Couldn't open %s: %s\n", dev, strerror(errno)); + pr_err("Couldn't open %s: %s\n", dev, strerror(errno)); return 1; } @@ -1016,8 +1016,8 @@ int WaitClean(char *dev, int sock, int verbose) mdi = sysfs_read(fd, devnum, GET_VERSION|GET_LEVEL|GET_SAFEMODE); if (!mdi) { if (verbose) - fprintf(stderr, Name ": Failed to read sysfs attributes for " - "%s\n", dev); + pr_err("Failed to read sysfs attributes for " + "%s\n", dev); close(fd); return 0; } @@ -1080,7 +1080,7 @@ int WaitClean(char *dev, int sock, int verbose) } else rv = 1; if (rv && verbose) - fprintf(stderr, Name ": Error waiting for %s to be clean\n", + pr_err("Error waiting for %s to be clean\n", dev); /* restore the original safe_mode_delay */ diff --git a/Query.c b/Query.c index 0b15e286..b9c209f7 100644 --- a/Query.c +++ b/Query.c @@ -47,7 +47,7 @@ int Query(char *dev) char *activity; if (fd < 0){ - fprintf(stderr, Name ": cannot open %s: %s\n", + pr_err("cannot open %s: %s\n", dev, strerror(errno)); return 1; } diff --git a/bitmap.c b/bitmap.c index c27688c5..351f08a0 100644 --- a/bitmap.c +++ b/bitmap.c @@ -133,7 +133,7 @@ bitmap_info_t *bitmap_fd_read(int fd, int brief) unsigned int n, skip; if (posix_memalign(&buf, 4096, 8192) != 0) { - fprintf(stderr, Name ": failed to allocate 8192 bytes\n"); + pr_err("failed to allocate 8192 bytes\n"); return NULL; } n = read(fd, buf, 8192); @@ -141,10 +141,10 @@ bitmap_info_t *bitmap_fd_read(int fd, int brief) info = malloc(sizeof(*info)); if (info == NULL) { #if __GNUC__ < 3 - fprintf(stderr, Name ": failed to allocate %d bytes\n", + pr_err("failed to allocate %d bytes\n", (int)sizeof(*info)); #else - fprintf(stderr, Name ": failed to allocate %zd bytes\n", + pr_err("failed to allocate %zd bytes\n", sizeof(*info)); #endif free(buf); @@ -152,8 +152,8 @@ bitmap_info_t *bitmap_fd_read(int fd, int brief) } if (n < sizeof(info->sb)) { - fprintf(stderr, Name ": failed to read superblock of bitmap " - "file: %s\n", strerror(errno)); + pr_err("failed to read superblock of bitmap " + "file: %s\n", strerror(errno)); free(info); free(buf); return NULL; @@ -194,7 +194,7 @@ bitmap_info_t *bitmap_fd_read(int fd, int brief) } if (read_bits < total_bits) { /* file truncated... */ - fprintf(stderr, Name ": WARNING: bitmap file is not large " + pr_err("WARNING: bitmap file is not large " "enough for array size %llu!\n\n", (unsigned long long)info->sb.sync_size); total_bits = read_bits; @@ -214,14 +214,14 @@ bitmap_info_t *bitmap_file_read(char *filename, int brief, struct supertype **st struct supertype *st = *stp; if (stat(filename, &stb) < 0) { - fprintf(stderr, Name ": failed to find file %s: %s\n", + pr_err("failed to find file %s: %s\n", filename, strerror(errno)); return NULL; } if ((S_IFMT & stb.st_mode) == S_IFBLK) { fd = open(filename, O_RDONLY); if (fd < 0) { - fprintf(stderr, Name ": failed to open bitmap file %s: %s\n", + pr_err("failed to open bitmap file %s: %s\n", filename, strerror(errno)); return NULL; } @@ -231,7 +231,7 @@ bitmap_info_t *bitmap_file_read(char *filename, int brief, struct supertype **st /* just look at device... */ lseek(fd, 0, 0); } else if (!st->ss->locate_bitmap) { - fprintf(stderr, Name ": No bitmap possible with %s metadata\n", + pr_err("No bitmap possible with %s metadata\n", st->ss->name); return NULL; } else @@ -242,7 +242,7 @@ bitmap_info_t *bitmap_file_read(char *filename, int brief, struct supertype **st } else { fd = open(filename, O_RDONLY|O_DIRECT); if (fd < 0) { - fprintf(stderr, Name ": failed to open bitmap file %s: %s\n", + pr_err("failed to open bitmap file %s: %s\n", filename, strerror(errno)); return NULL; } @@ -286,12 +286,12 @@ int ExamineBitmap(char *filename, int brief, struct supertype *st) printf(" Filename : %s\n", filename); printf(" Magic : %08x\n", sb->magic); if (sb->magic != BITMAP_MAGIC) { - fprintf(stderr, Name ": invalid bitmap magic 0x%x, the bitmap file appears to be corrupted\n", sb->magic); + pr_err("invalid bitmap magic 0x%x, the bitmap file appears to be corrupted\n", sb->magic); } printf(" Version : %d\n", sb->version); if (sb->version < BITMAP_MAJOR_LO || sb->version > BITMAP_MAJOR_HI) { - fprintf(stderr, Name ": unknown bitmap version %d, either the bitmap file is corrupted or you need to upgrade your tools\n", sb->version); + pr_err("unknown bitmap version %d, either the bitmap file is corrupted or you need to upgrade your tools\n", sb->version); goto free_info; } @@ -357,13 +357,13 @@ int CreateBitmap(char *filename, int force, char uuid[16], long long bytes, filesize; if (!force && access(filename, F_OK) == 0) { - fprintf(stderr, Name ": bitmap file %s already exists, use --force to overwrite\n", filename); + pr_err("bitmap file %s already exists, use --force to overwrite\n", filename); return rv; } fp = fopen(filename, "w"); if (fp == NULL) { - fprintf(stderr, Name ": failed to open bitmap file %s: %s\n", + pr_err("failed to open bitmap file %s: %s\n", filename, strerror(errno)); return rv; } @@ -393,7 +393,7 @@ int CreateBitmap(char *filename, int force, char uuid[16], sb_cpu_to_le(&sb); /* convert to on-disk byte ordering */ if (fwrite(&sb, sizeof(sb), 1, fp) != 1) { - fprintf(stderr, Name ": failed to write superblock to bitmap file %s: %s\n", filename, strerror(errno)); + pr_err("failed to write superblock to bitmap file %s: %s\n", filename, strerror(errno)); goto out; } @@ -410,7 +410,7 @@ int CreateBitmap(char *filename, int force, char uuid[16], while (bytes > 0) { if (fwrite(block, sizeof(block), 1, fp) != 1) { - fprintf(stderr, Name ": failed to write bitmap file %s: %s\n", filename, strerror(errno)); + pr_err("failed to write bitmap file %s: %s\n", filename, strerror(errno)); goto out; } bytes -= sizeof(block); diff --git a/config.c b/config.c index d8f48e13..c79d3826 100644 --- a/config.c +++ b/config.c @@ -159,7 +159,7 @@ struct mddev_dev *load_partitions(void) char buf[1024]; struct mddev_dev *rv = NULL; if (f == NULL) { - fprintf(stderr, Name ": cannot open /proc/partitions\n"); + pr_err("cannot open /proc/partitions\n"); return NULL; } while (fgets(buf, 1024, f)) { @@ -264,7 +264,7 @@ int parse_auto(char *str, char *msg, int config) (len >= 4 && strncasecmp(str,"part",4)==0)) { autof = 6; } else { - fprintf(stderr, Name ": %s arg of \"%s\" unrecognised: use no,yes,md,mdp,part\n" + pr_err("%s arg of \"%s\" unrecognised: use no,yes,md,mdp,part\n" " optionally followed by a number.\n", msg, str); exit(2); @@ -284,7 +284,7 @@ static void createline(char *line) createinfo.autof = parse_auto(w+5, "auto=", 1); else if (strncasecmp(w, "owner=", 6) == 0) { if (w[6] == 0) { - fprintf(stderr, Name ": missing owner name\n"); + pr_err("missing owner name\n"); continue; } createinfo.uid = strtoul(w+6, &ep, 10); @@ -295,11 +295,11 @@ static void createline(char *line) if (pw) createinfo.uid = pw->pw_uid; else - fprintf(stderr, Name ": CREATE user %s not found\n", w+6); + pr_err("CREATE user %s not found\n", w+6); } } else if (strncasecmp(w, "group=", 6) == 0) { if (w[6] == 0) { - fprintf(stderr, Name ": missing group name\n"); + pr_err("missing group name\n"); continue; } createinfo.gid = strtoul(w+6, &ep, 10); @@ -310,17 +310,17 @@ static void createline(char *line) if (gr) createinfo.gid = gr->gr_gid; else - fprintf(stderr, Name ": CREATE group %s not found\n", w+6); + pr_err("CREATE group %s not found\n", w+6); } } else if (strncasecmp(w, "mode=", 5) == 0) { if (w[5] == 0) { - fprintf(stderr, Name ": missing CREATE mode\n"); + pr_err("missing CREATE mode\n"); continue; } createinfo.mode = strtoul(w+5, &ep, 8); if (*ep != 0) { createinfo.mode = 0600; - fprintf(stderr, Name ": unrecognised CREATE mode %s\n", + pr_err("unrecognised CREATE mode %s\n", w+5); } } else if (strncasecmp(w, "metadata=", 9) == 0) { @@ -330,14 +330,14 @@ static void createline(char *line) createinfo.supertype = superlist[i]->match_metadata_desc(w+9); if (!createinfo.supertype) - fprintf(stderr, Name ": metadata format %s unknown, ignoring\n", + pr_err("metadata format %s unknown, ignoring\n", w+9); } else if (strncasecmp(w, "symlinks=yes", 12) == 0) createinfo.symlinks = 1; else if (strncasecmp(w, "symlinks=no", 11) == 0) createinfo.symlinks = 0; else { - fprintf(stderr, Name ": unrecognised word on CREATE line: %s\n", + pr_err("unrecognised word on CREATE line: %s\n", w); } } @@ -356,7 +356,7 @@ void devline(char *line) cd->next = cdevlist; cdevlist = cd; } else { - fprintf(stderr, Name ": unreconised word on DEVICE line: %s\n", + pr_err("unreconised word on DEVICE line: %s\n", w); } } @@ -421,64 +421,64 @@ void arrayline(char *line) ) { /* This is acceptable */; if (mis.devname) - fprintf(stderr, Name ": only give one " + pr_err("only give one " "device per ARRAY line: %s and %s\n", mis.devname, w); else mis.devname = w; }else { - fprintf(stderr, Name ": %s is an invalid name for " + pr_err("%s is an invalid name for " "an md device - ignored.\n", w); } } else if (strncasecmp(w, "uuid=", 5)==0 ) { if (mis.uuid_set) - fprintf(stderr, Name ": only specify uuid once, %s ignored.\n", + pr_err("only specify uuid once, %s ignored.\n", w); else { if (parse_uuid(w+5, mis.uuid)) mis.uuid_set = 1; else - fprintf(stderr, Name ": bad uuid: %s\n", w); + pr_err("bad uuid: %s\n", w); } } else if (strncasecmp(w, "super-minor=", 12)==0 ) { if (mis.super_minor != UnSet) - fprintf(stderr, Name ": only specify super-minor once, %s ignored.\n", + pr_err("only specify super-minor once, %s ignored.\n", w); else { char *endptr; int minor = strtol(w+12, &endptr, 10); if (w[12]==0 || endptr[0]!=0 || minor < 0) - fprintf(stderr, Name ": invalid super-minor number: %s\n", + pr_err("invalid super-minor number: %s\n", w); else mis.super_minor = minor; } } else if (strncasecmp(w, "name=", 5)==0) { if (mis.name[0]) - fprintf(stderr, Name ": only specify name once, %s ignored.\n", + pr_err("only specify name once, %s ignored.\n", w); else if (strlen(w+5) > 32) - fprintf(stderr, Name ": name too long, ignoring %s\n", w); + pr_err("name too long, ignoring %s\n", w); else strcpy(mis.name, w+5); } else if (strncasecmp(w, "bitmap=", 7) == 0) { if (mis.bitmap_file) - fprintf(stderr, Name ": only specify bitmap file once. %s ignored\n", + pr_err("only specify bitmap file once. %s ignored\n", w); else mis.bitmap_file = strdup(w+7); } else if (strncasecmp(w, "devices=", 8 ) == 0 ) { if (mis.devices) - fprintf(stderr, Name ": only specify devices once (use a comma separated list). %s ignored\n", + pr_err("only specify devices once (use a comma separated list). %s ignored\n", w); else mis.devices = strdup(w+8); } else if (strncasecmp(w, "spare-group=", 12) == 0 ) { if (mis.spare_group) - fprintf(stderr, Name ": only specify one spare group per array. %s ignored.\n", + pr_err("only specify one spare group per array. %s ignored.\n", w); else mis.spare_group = strdup(w+12); @@ -502,7 +502,7 @@ void arrayline(char *line) mis.st = superlist[i]->match_metadata_desc(w+9); if (!mis.st) - fprintf(stderr, Name ": metadata format %s unknown, ignored.\n", w+9); + pr_err("metadata format %s unknown, ignored.\n", w+9); } else if (strncasecmp(w, "auto=", 5) == 0 ) { /* whether to create device special files as needed */ mis.autof = parse_auto(w+5, "auto type", 0); @@ -514,14 +514,14 @@ void arrayline(char *line) * or a uuid */ mis.container = strdup(w+10); } else { - fprintf(stderr, Name ": unrecognised word on ARRAY line: %s\n", + pr_err("unrecognised word on ARRAY line: %s\n", w); } } if (mis.uuid_set == 0 && mis.devices == NULL && mis.super_minor == UnSet && mis.name[0] == 0 && (mis.container == NULL || mis.member == NULL)) - fprintf(stderr, Name ": ARRAY line %s has no identity information.\n", mis.devname); + pr_err("ARRAY line %s has no identity information.\n", mis.devname); else { mi = malloc(sizeof(*mi)); *mi = mis; @@ -541,7 +541,7 @@ void mailline(char *line) if (alert_email == NULL) alert_email = strdup(w); else - fprintf(stderr, Name ": excess address on MAIL line: %s - ignored\n", + pr_err("excess address on MAIL line: %s - ignored\n", w); } } @@ -575,7 +575,7 @@ void programline(char *line) if (alert_program == NULL) alert_program = strdup(w); else - fprintf(stderr, Name ": excess program on PROGRAM line: %s - ignored\n", + pr_err("excess program on PROGRAM line: %s - ignored\n", w); } } @@ -595,7 +595,7 @@ void homehostline(char *line) else home_host = strdup(w); }else - fprintf(stderr, Name ": excess host name on HOMEHOST line: %s - ignored\n", + pr_err("excess host name on HOMEHOST line: %s - ignored\n", w); } } @@ -615,7 +615,7 @@ void autoline(char *line) int i; if (auto_seen) { - fprintf(stderr, Name ": AUTO line may only be give once." + pr_err("AUTO line may only be give once." " Subsequent lines ignored\n"); return; } @@ -790,7 +790,7 @@ void load_conffile(void) policyline(line, rule_part); break; default: - fprintf(stderr, Name ": Unknown keyword %s\n", line); + pr_err("Unknown keyword %s\n", line); } free_line(line); } @@ -1032,33 +1032,29 @@ struct mddev_ident *conf_match(struct supertype *st, same_uuid(array_list->uuid, info->uuid, st->ss->swapuuid) == 0) { if (verbose >= 2 && array_list->devname) - fprintf(stderr, Name - ": UUID differs from %s.\n", - array_list->devname); + pr_err("UUID differs from %s.\n", + array_list->devname); continue; } if (array_list->name[0] && strcasecmp(array_list->name, info->name) != 0) { if (verbose >= 2 && array_list->devname) - fprintf(stderr, Name - ": Name differs from %s.\n", - array_list->devname); + pr_err("Name differs from %s.\n", + array_list->devname); continue; } if (array_list->devices && devname && !match_oneof(array_list->devices, devname)) { if (verbose >= 2 && array_list->devname) - fprintf(stderr, Name - ": Not a listed device for %s.\n", - array_list->devname); + pr_err("Not a listed device for %s.\n", + array_list->devname); continue; } if (array_list->super_minor != UnSet && array_list->super_minor != info->array.md_minor) { if (verbose >= 2 && array_list->devname) - fprintf(stderr, Name - ": Different super-minor to %s.\n", - array_list->devname); + pr_err("Different super-minor to %s.\n", + array_list->devname); continue; } if (!array_list->uuid_set && @@ -1066,10 +1062,9 @@ struct mddev_ident *conf_match(struct supertype *st, !array_list->devices && array_list->super_minor == UnSet) { if (verbose >= 2 && array_list->devname) - fprintf(stderr, Name - ": %s doesn't have any identifying" - " information.\n", - array_list->devname); + pr_err("%s doesn't have any identifying" + " information.\n", + array_list->devname); continue; } /* FIXME, should I check raid_disks and level too?? */ @@ -1077,15 +1072,13 @@ struct mddev_ident *conf_match(struct supertype *st, if (match) { if (verbose >= 0) { if (match->devname && array_list->devname) - fprintf(stderr, Name - ": we match both %s and %s - " - "cannot decide which to use.\n", - match->devname, - array_list->devname); + pr_err("we match both %s and %s - " + "cannot decide which to use.\n", + match->devname, + array_list->devname); else - fprintf(stderr, Name - ": multiple lines in mdadm.conf" - " match\n"); + pr_err("multiple lines in mdadm.conf" + " match\n"); } if (rvp) *rvp = 2; @@ -1113,15 +1106,14 @@ int conf_verify_devnames(struct mddev_ident *array_list) if (a1->uuid_set && a2->uuid_set) { char nbuf[64]; __fname_from_uuid(a1->uuid, 0, nbuf, ':'); - fprintf(stderr, - Name ": Devices %s and ", - nbuf); + pr_err("Devices %s and ", + nbuf); __fname_from_uuid(a2->uuid, 0, nbuf, ':'); fprintf(stderr, "%s have the same name: %s\n", nbuf, a1->devname); } else - fprintf(stderr, Name ": Device %s given twice" + pr_err("Device %s given twice" " in config file\n", a1->devname); return 1; } diff --git a/mdadm.c b/mdadm.c index 1d050e4d..fa3da9fd 100644 --- a/mdadm.c +++ b/mdadm.c @@ -289,7 +289,7 @@ int main(int argc, char *argv[]) /* everybody happy ! */ } else if (mode && newmode != mode) { /* not allowed.. */ - fprintf(stderr, Name ": "); + pr_err(""); if (option_index >= 0) fprintf(stderr, "--%s", long_options[option_index].name); else @@ -301,7 +301,7 @@ int main(int argc, char *argv[]) } else if (!mode && newmode) { mode = newmode; if (mode == MISC && devs_found) { - fprintf(stderr, Name ": No action given for %s in --misc mode\n", + pr_err("No action given for %s in --misc mode\n", devlist->devname); fprintf(stderr," Action options must come before device names\n"); exit(2); @@ -320,7 +320,7 @@ int main(int argc, char *argv[]) if (devs_found == 0) { dv = malloc(sizeof(*dv)); if (dv == NULL) { - fprintf(stderr, Name ": malloc failed\n"); + pr_err("malloc failed\n"); exit(3); } dv->devname = optarg; @@ -336,14 +336,14 @@ int main(int argc, char *argv[]) continue; } /* No mode yet, and this is the second device ... */ - fprintf(stderr, Name ": An option must be given to set the mode before a second device\n" + pr_err("An option must be given to set the mode before a second device\n" " (%s) is listed\n", optarg); exit(2); } if (option_index >= 0) - fprintf(stderr, Name ": --%s", long_options[option_index].name); + pr_err("--%s", long_options[option_index].name); else - fprintf(stderr, Name ": -%c", opt); + pr_err("-%c", opt); fprintf(stderr, " does not set the mode, and so cannot be the first option.\n"); exit(2); } @@ -365,18 +365,18 @@ int main(int argc, char *argv[]) /* an undecorated option - must be a device name. */ if (devs_found > 0 && mode == MANAGE && !devmode) { - fprintf(stderr, Name ": Must give one of -a/-r/-f" + pr_err("Must give one of -a/-r/-f" " for subsequent devices at %s\n", optarg); exit(2); } if (devs_found > 0 && mode == GROW && !devmode) { - fprintf(stderr, Name ": Must give -a/--add for" - " devices to add: %s\n", optarg); + pr_err("Must give -a/--add for" + " devices to add: %s\n", optarg); exit(2); } dv = malloc(sizeof(*dv)); if (dv == NULL) { - fprintf(stderr, Name ": malloc failed\n"); + pr_err("malloc failed\n"); exit(3); } dv->devname = optarg; @@ -403,13 +403,13 @@ int main(int argc, char *argv[]) case O(BUILD,'c'): /* chunk or rounding */ case O(BUILD,ChunkSize): /* chunk or rounding */ if (chunk) { - fprintf(stderr, Name ": chunk/rounding may only be specified once. " + pr_err("chunk/rounding may only be specified once. " "Second value is %s.\n", optarg); exit(2); } chunk = parse_size(optarg); if (chunk < 8 || (chunk&1)) { - fprintf(stderr, Name ": invalid chunk/rounding value: %s\n", + pr_err("invalid chunk/rounding value: %s\n", optarg); exit(2); } @@ -422,14 +422,14 @@ int main(int argc, char *argv[]) case O(ASSEMBLE,'e'): case O(MISC,'e'): /* set metadata (superblock) information */ if (ss) { - fprintf(stderr, Name ": metadata information already given\n"); + pr_err("metadata information already given\n"); exit(2); } for(i=0; !ss && superlist[i]; i++) ss = superlist[i]->match_metadata_desc(optarg); if (!ss) { - fprintf(stderr, Name ": unrecognised metadata identifier: %s\n", optarg); + pr_err("unrecognised metadata identifier: %s\n", optarg); exit(2); } continue; @@ -454,7 +454,7 @@ int main(int argc, char *argv[]) case O(CREATE,'z'): case O(BUILD,'z'): /* size */ if (size >= 0) { - fprintf(stderr, Name ": size may only be specified once. " + pr_err("size may only be specified once. " "Second value is %s.\n", optarg); exit(2); } @@ -463,7 +463,7 @@ int main(int argc, char *argv[]) else { size = parse_size(optarg); if (size < 8) { - fprintf(stderr, Name ": invalid size: %s\n", + pr_err("invalid size: %s\n", optarg); exit(2); } @@ -474,7 +474,7 @@ int main(int argc, char *argv[]) case O(GROW,'Z'): /* array size */ if (array_size >= 0) { - fprintf(stderr, Name ": array-size may only be specified once. " + pr_err("array-size may only be specified once. " "Second value is %s.\n", optarg); exit(2); } @@ -483,7 +483,7 @@ int main(int argc, char *argv[]) else { array_size = parse_size(optarg); if (array_size <= 0) { - fprintf(stderr, Name ": invalid array size: %s\n", + pr_err("invalid array size: %s\n", optarg); exit(2); } @@ -494,13 +494,13 @@ int main(int argc, char *argv[]) case O(CREATE,'l'): case O(BUILD,'l'): /* set raid level*/ if (level != UnSet) { - fprintf(stderr, Name ": raid level may only be set once. " + pr_err("raid level may only be set once. " "Second value is %s.\n", optarg); exit(2); } level = map_name(pers, optarg); if (level == UnSet) { - fprintf(stderr, Name ": invalid raid level: %s\n", + pr_err("invalid raid level: %s\n", optarg); exit(2); } @@ -508,12 +508,12 @@ int main(int argc, char *argv[]) level != LEVEL_MULTIPATH && level != LEVEL_FAULTY && level != 10 && mode == BUILD) { - fprintf(stderr, Name ": Raid level %s not permitted with --build.\n", + pr_err("Raid level %s not permitted with --build.\n", optarg); exit(2); } if (sparedisks > 0 && level < 1 && level >= -1) { - fprintf(stderr, Name ": raid level %s is incompatible with spare-devices setting.\n", + pr_err("raid level %s is incompatible with spare-devices setting.\n", optarg); exit(2); } @@ -523,8 +523,8 @@ int main(int argc, char *argv[]) case O(GROW, 'p'): /* new layout */ case O(GROW, Layout): if (layout_str) { - fprintf(stderr,Name ": layout may only be sent once. " - "Second value was %s\n", optarg); + pr_err("layout may only be sent once. " + "Second value was %s\n", optarg); exit(2); } layout_str = optarg; @@ -536,23 +536,23 @@ int main(int argc, char *argv[]) case O(BUILD,'p'): /* faulty layout */ case O(BUILD,Layout): if (layout != UnSet) { - fprintf(stderr,Name ": layout may only be sent once. " - "Second value was %s\n", optarg); + pr_err("layout may only be sent once. " + "Second value was %s\n", optarg); exit(2); } switch(level) { default: - fprintf(stderr, Name ": layout not meaningful for %s arrays.\n", + pr_err("layout not meaningful for %s arrays.\n", map_num(pers, level)); exit(2); case UnSet: - fprintf(stderr, Name ": raid level must be given before layout.\n"); + pr_err("raid level must be given before layout.\n"); exit(2); case 5: layout = map_name(r5layout, optarg); if (layout==UnSet) { - fprintf(stderr, Name ": layout %s not understood for raid5.\n", + pr_err("layout %s not understood for raid5.\n", optarg); exit(2); } @@ -560,7 +560,7 @@ int main(int argc, char *argv[]) case 6: layout = map_name(r6layout, optarg); if (layout==UnSet) { - fprintf(stderr, Name ": layout %s not understood for raid6.\n", + pr_err("layout %s not understood for raid6.\n", optarg); exit(2); } @@ -569,7 +569,7 @@ int main(int argc, char *argv[]) case 10: layout = parse_layout_10(optarg); if (layout < 0) { - fprintf(stderr, Name ": layout for raid10 must be 'nNN', 'oNN' or 'fNN' where NN is a number, not %s\n", optarg); + pr_err("layout for raid10 must be 'nNN', 'oNN' or 'fNN' where NN is a number, not %s\n", optarg); exit(2); } break; @@ -579,7 +579,7 @@ int main(int argc, char *argv[]) */ layout = parse_layout_faulty(optarg); if (layout == -1) { - fprintf(stderr, Name ": layout %s not understood for faulty.\n", + pr_err("layout %s not understood for faulty.\n", optarg); exit(2); } @@ -597,13 +597,13 @@ int main(int argc, char *argv[]) case O(CREATE,'n'): case O(BUILD,'n'): /* number of raid disks */ if (raiddisks) { - fprintf(stderr, Name ": raid-devices set twice: %d and %s\n", + pr_err("raid-devices set twice: %d and %s\n", raiddisks, optarg); exit(2); } raiddisks = strtol(optarg, &c, 10); if (!optarg[0] || *c || raiddisks<=0) { - fprintf(stderr, Name ": invalid number of raid devices: %s\n", + pr_err("invalid number of raid devices: %s\n", optarg); exit(2); } @@ -612,18 +612,18 @@ int main(int argc, char *argv[]) case O(CREATE,'x'): /* number of spare (eXtra) disks */ if (sparedisks) { - fprintf(stderr,Name ": spare-devices set twice: %d and %s\n", - sparedisks, optarg); + pr_err("spare-devices set twice: %d and %s\n", + sparedisks, optarg); exit(2); } if (level != UnSet && level <= 0 && level >= -1) { - fprintf(stderr, Name ": spare-devices setting is incompatible with raid level %d\n", + pr_err("spare-devices setting is incompatible with raid level %d\n", level); exit(2); } sparedisks = strtol(optarg, &c, 10); if (!optarg[0] || *c || sparedisks < 0) { - fprintf(stderr, Name ": invalid number of spare-devices: %s\n", + pr_err("invalid number of spare-devices: %s\n", optarg); exit(2); } @@ -668,14 +668,14 @@ int main(int argc, char *argv[]) case O(CREATE,'u'): /* uuid of array */ case O(ASSEMBLE,'u'): /* uuid of array */ if (ident.uuid_set) { - fprintf(stderr, Name ": uuid cannot be set twice. " + pr_err("uuid cannot be set twice. " "Second value %s.\n", optarg); exit(2); } if (parse_uuid(optarg, ident.uuid)) ident.uuid_set = 1; else { - fprintf(stderr,Name ": Bad uuid: %s\n", optarg); + pr_err("Bad uuid: %s\n", optarg); exit(2); } continue; @@ -684,16 +684,16 @@ int main(int argc, char *argv[]) case O(ASSEMBLE,'N'): case O(MISC,'N'): if (ident.name[0]) { - fprintf(stderr, Name ": name cannot be set twice. " + pr_err("name cannot be set twice. " "Second value %s.\n", optarg); exit(2); } if (mode == MISC && !subarray) { - fprintf(stderr, Name ": -N/--name only valid with --update-subarray in misc mode\n"); + pr_err("-N/--name only valid with --update-subarray in misc mode\n"); exit(2); } if (strlen(optarg) > 32) { - fprintf(stderr, Name ": name '%s' is too long, 32 chars max.\n", + pr_err("name '%s' is too long, 32 chars max.\n", optarg); exit(2); } @@ -703,7 +703,7 @@ int main(int argc, char *argv[]) case O(ASSEMBLE,'m'): /* super-minor for array */ case O(ASSEMBLE,SuperMinor): if (ident.super_minor != UnSet) { - fprintf(stderr, Name ": super-minor cannot be set twice. " + pr_err("super-minor cannot be set twice. " "Second value: %s.\n", optarg); exit(2); } @@ -712,7 +712,7 @@ int main(int argc, char *argv[]) else { ident.super_minor = strtoul(optarg, &cp, 10); if (!optarg[0] || *cp) { - fprintf(stderr, Name ": Bad super-minor number: %s.\n", optarg); + pr_err("Bad super-minor number: %s.\n", optarg); exit(2); } } @@ -721,13 +721,13 @@ int main(int argc, char *argv[]) case O(ASSEMBLE,'U'): /* update the superblock */ case O(MISC,'U'): if (update) { - fprintf(stderr, Name ": Can only update one aspect" + pr_err("Can only update one aspect" " of superblock, both %s and %s given.\n", update, optarg); exit(2); } if (mode == MISC && !subarray) { - fprintf(stderr, Name ": Only subarrays can be" + pr_err("Only subarrays can be" " updated in misc mode\n"); exit(2); } @@ -752,16 +752,15 @@ int main(int argc, char *argv[]) continue; if (strcmp(update, "byteorder")==0) { if (ss) { - fprintf(stderr, - Name ": must not set metadata" - " type with --update=byteorder.\n"); + pr_err("must not set metadata" + " type with --update=byteorder.\n"); exit(2); } for(i=0; !ss && superlist[i]; i++) ss = superlist[i]->match_metadata_desc( "0.swap"); if (!ss) { - fprintf(stderr, Name ": INTERNAL ERROR" + pr_err("INTERNAL ERROR" " cannot find 0.swap\n"); exit(2); } @@ -787,26 +786,26 @@ int main(int argc, char *argv[]) case O(MANAGE,'U'): /* update=devicesize is allowed with --re-add */ if (devmode != 'a' || re_add != 1) { - fprintf(stderr, Name "--update in Manage mode only" + pr_err("--update in Manage mode only" " allowed with --re-add.\n"); exit(1); } if (update) { - fprintf(stderr, Name ": Can only update one aspect" + pr_err("Can only update one aspect" " of superblock, both %s and %s given.\n", update, optarg); exit(2); } update = optarg; if (strcmp(update, "devicesize") != 0) { - fprintf(stderr, Name ": only 'devicesize' can be" + pr_err("only 'devicesize' can be" " updated with --re-add\n"); exit(2); } continue; case O(INCREMENTAL,NoDegraded): - fprintf(stderr, Name ": --no-degraded is deprecated in Incremental mode\n"); + pr_err("--no-degraded is deprecated in Incremental mode\n"); case O(ASSEMBLE,NoDegraded): /* --no-degraded */ runstop = -1; /* --stop isn't allowed for --assemble, * so we overload slightly */ @@ -821,7 +820,7 @@ int main(int argc, char *argv[]) case O(MONITOR,'c'): case O(MONITOR,ConfigFile): if (configfile) { - fprintf(stderr, Name ": configfile cannot be set twice. " + pr_err("configfile cannot be set twice. " "Second value is %s.\n", optarg); exit(2); } @@ -839,7 +838,7 @@ int main(int argc, char *argv[]) case O(MONITOR,'m'): /* mail address */ case O(MONITOR,EMail): if (mailaddr) - fprintf(stderr, Name ": only specify one mailaddress. %s ignored.\n", + pr_err("only specify one mailaddress. %s ignored.\n", optarg); else mailaddr = optarg; @@ -848,7 +847,7 @@ int main(int argc, char *argv[]) case O(MONITOR,'p'): /* alert program */ case O(MONITOR,ProgramOpt): /* alert program */ if (program) - fprintf(stderr, Name ": only specify one alter program. %s ignored.\n", + pr_err("only specify one alter program. %s ignored.\n", optarg); else program = optarg; @@ -858,7 +857,7 @@ int main(int argc, char *argv[]) case O(MONITOR,Increment): increments = atoi(optarg); if (increments > 99 || increments < 1) { - fprintf(stderr, Name ": please specify positive integer between 1 and 99 as rebuild increments.\n"); + pr_err("please specify positive integer between 1 and 99 as rebuild increments.\n"); exit(2); } continue; @@ -868,12 +867,12 @@ int main(int argc, char *argv[]) case O(BUILD,'d'): /* delay for bitmap updates */ case O(CREATE,'d'): if (delay) - fprintf(stderr, Name ": only specify delay once. %s ignored.\n", + pr_err("only specify delay once. %s ignored.\n", optarg); else { delay = strtol(optarg, &c, 10); if (!optarg[0] || *c || delay<1) { - fprintf(stderr, Name ": invalid delay: %s\n", + pr_err("invalid delay: %s\n", optarg); exit(2); } @@ -885,7 +884,7 @@ int main(int argc, char *argv[]) continue; case O(MONITOR,'i'): /* pid */ if (pidfile) - fprintf(stderr, Name ": only specify one pid file. %s ignored.\n", + pr_err("only specify one pid file. %s ignored.\n", optarg); else pidfile = optarg; @@ -938,14 +937,14 @@ int main(int argc, char *argv[]) case O(BUILD,'R'): case O(CREATE,'R'): /* Run the array */ if (runstop < 0) { - fprintf(stderr, Name ": Cannot both Stop and Run an array\n"); + pr_err("Cannot both Stop and Run an array\n"); exit(2); } runstop = 1; continue; case O(MANAGE,'S'): if (runstop > 0) { - fprintf(stderr, Name ": Cannot both Run and Stop an array\n"); + pr_err("Cannot both Run and Stop an array\n"); exit(2); } runstop = -1; @@ -971,7 +970,7 @@ int main(int argc, char *argv[]) case O(MISC, UpdateSubarray): if (opt == KillSubarray || opt == UpdateSubarray) { if (subarray) { - fprintf(stderr, Name ": subarray can only" + pr_err("subarray can only" " be specified once\n"); exit(2); } @@ -979,7 +978,7 @@ int main(int argc, char *argv[]) } if (devmode && devmode != opt && (devmode == 'E' || (opt == 'E' && devmode != 'Q'))) { - fprintf(stderr, Name ": --examine/-E cannot be given with "); + pr_err("--examine/-E cannot be given with "); if (devmode == 'E') { if (option_index >= 0) fprintf(stderr, "--%s\n", @@ -996,11 +995,11 @@ int main(int argc, char *argv[]) continue; case O(MISC, UdevRules): if (devmode && devmode != opt) { - fprintf(stderr, Name ": --udev-rules must" - " be the only option.\n"); + pr_err("--udev-rules must" + " be the only option.\n"); } else { if (udev_filename) - fprintf(stderr, Name ": only specify one udev " + pr_err("only specify one udev " "rule filename. %s ignored.\n", optarg); else @@ -1014,7 +1013,7 @@ int main(int argc, char *argv[]) case O(MISC, Sparc22): if (devmode != 'E') { - fprintf(stderr, Name ": --sparc2.2 only allowed with --examine\n"); + pr_err("--sparc2.2 only allowed with --examine\n"); exit(2); } SparcAdjust = 1; @@ -1023,16 +1022,16 @@ int main(int argc, char *argv[]) case O(ASSEMBLE,'b'): /* here we simply set the bitmap file */ case O(ASSEMBLE,Bitmap): if (!optarg) { - fprintf(stderr, Name ": bitmap file needed with -b in --assemble mode\n"); + pr_err("bitmap file needed with -b in --assemble mode\n"); exit(2); } if (strcmp(optarg, "internal")==0) { - fprintf(stderr, Name ": there is no need to specify --bitmap when assembling arrays with internal bitmaps\n"); + pr_err("there is no need to specify --bitmap when assembling arrays with internal bitmaps\n"); continue; } bitmap_fd = open(optarg, O_RDWR); if (!*optarg || bitmap_fd < 0) { - fprintf(stderr, Name ": cannot open bitmap file %s: %s\n", optarg, strerror(errno)); + pr_err("cannot open bitmap file %s: %s\n", optarg, strerror(errno)); exit(2); } ident.bitmap_fd = bitmap_fd; /* for Assemble */ @@ -1044,7 +1043,7 @@ int main(int argc, char *argv[]) * or from which assemble might recover a backup */ if (backup_file) { - fprintf(stderr, Name ": backup file already specified, rejecting %s\n", optarg); + pr_err("backup file already specified, rejecting %s\n", optarg); exit(2); } backup_file = optarg; @@ -1067,7 +1066,7 @@ int main(int argc, char *argv[]) case O(CREATE,'b'): case O(CREATE,Bitmap): /* here we create the bitmap */ if (strcmp(optarg, "none") == 0) { - fprintf(stderr, Name ": '--bitmap none' only" + pr_err("'--bitmap none' only" " supported for --grow\n"); exit(2); } @@ -1081,7 +1080,7 @@ int main(int argc, char *argv[]) continue; } /* probable typo */ - fprintf(stderr, Name ": bitmap file must contain a '/', or be 'internal', or 'none'\n" + pr_err("bitmap file must contain a '/', or be 'internal', or 'none'\n" " not '%s'\n", optarg); exit(2); @@ -1091,9 +1090,8 @@ int main(int argc, char *argv[]) bitmap_chunk = parse_size(optarg); if (bitmap_chunk <= 0 || bitmap_chunk & (bitmap_chunk - 1)) { - fprintf(stderr, - Name ": invalid bitmap chunksize: %s\n", - optarg); + pr_err("invalid bitmap chunksize: %s\n", + optarg); exit(2); } bitmap_chunk = bitmap_chunk * 512; @@ -1107,7 +1105,7 @@ int main(int argc, char *argv[]) write_behind = strtol(optarg, &c, 10); if (write_behind < 0 || *c || write_behind > 16383) { - fprintf(stderr, Name ": Invalid value for maximum outstanding write-behind writes: %s.\n\tMust be between 0 and 16383.\n", optarg); + pr_err("Invalid value for maximum outstanding write-behind writes: %s.\n\tMust be between 0 and 16383.\n", optarg); exit(2); } } @@ -1125,11 +1123,11 @@ int main(int argc, char *argv[]) * an error */ if (option_index > 0) - fprintf(stderr, Name ":option --%s not valid in %s mode\n", + pr_err(":option --%s not valid in %s mode\n", long_options[option_index].name, map_num(modes, mode)); else - fprintf(stderr, Name ": option -%c not valid in %s mode\n", + pr_err("option -%c not valid in %s mode\n", opt, map_num(modes, mode)); exit(2); @@ -1166,7 +1164,7 @@ int main(int argc, char *argv[]) else if (strcasecmp(symlinks, "no") == 0) ci->symlinks = 0; else { - fprintf(stderr, Name ": option --symlinks must be 'no' or 'yes'\n"); + pr_err("option --symlinks must be 'no' or 'yes'\n"); exit(2); } } @@ -1184,11 +1182,11 @@ int main(int argc, char *argv[]) || mode == GROW || (mode == ASSEMBLE && ! scan)) { if (devs_found < 1) { - fprintf(stderr, Name ": an md device must be given in this mode\n"); + pr_err("an md device must be given in this mode\n"); exit(2); } if ((int)ident.super_minor == -2 && autof) { - fprintf(stderr, Name ": --super-minor=dev is incompatible with --auto\n"); + pr_err("--super-minor=dev is incompatible with --auto\n"); exit(2); } if (mode == MANAGE || mode == GROW) { @@ -1199,14 +1197,14 @@ int main(int argc, char *argv[]) /* non-existent device is OK */ mdfd = open_mddev(devlist->devname, 0); if (mdfd == -2) { - fprintf(stderr, Name ": device %s exists but is not an " + pr_err("device %s exists but is not an " "md array.\n", devlist->devname); exit(1); } if ((int)ident.super_minor == -2) { struct stat stb; if (mdfd < 0) { - fprintf(stderr, Name ": --super-minor=dev given, and " + pr_err("--super-minor=dev given, and " "listed device %s doesn't exist.\n", devlist->devname); exit(1); @@ -1225,7 +1223,7 @@ int main(int argc, char *argv[]) if (raiddisks) { if (raiddisks == 1 && !force && level != LEVEL_FAULTY) { - fprintf(stderr, Name ": '1' is an unusual number of drives for an array, so it is probably\n" + pr_err("'1' is an unusual number of drives for an array, so it is probably\n" " a mistake. If you really mean it you will need to specify --force before\n" " setting the number of drives.\n"); exit(2); @@ -1249,7 +1247,7 @@ int main(int argc, char *argv[]) || (mode == MONITOR && spare_sharing == 0)) /* Anyone may try this */; else if (geteuid() != 0) { - fprintf(stderr, Name ": must be super-user to perform this action\n"); + pr_err("must be super-user to perform this action\n"); exit(1); } @@ -1276,7 +1274,7 @@ int main(int argc, char *argv[]) /* Only a device has been given, so get details from config file */ struct mddev_ident *array_ident = conf_get_ident(devlist->devname); if (array_ident == NULL) { - fprintf(stderr, Name ": %s not identified in config file.\n", + pr_err("%s not identified in config file.\n", devlist->devname); rv |= 1; if (mdfd >= 0) @@ -1300,17 +1298,17 @@ int main(int argc, char *argv[]) freeze_reshape); else if (devs_found > 0) { if (update && devs_found > 1) { - fprintf(stderr, Name ": can only update a single array at a time\n"); + pr_err("can only update a single array at a time\n"); exit(1); } if (backup_file && devs_found > 1) { - fprintf(stderr, Name ": can only assemble a single array when providing a backup file.\n"); + pr_err("can only assemble a single array when providing a backup file.\n"); exit(1); } for (dv = devlist ; dv ; dv=dv->next) { struct mddev_ident *array_ident = conf_get_ident(dv->devname); if (array_ident == NULL) { - fprintf(stderr, Name ": %s not identified in config file.\n", + pr_err("%s not identified in config file.\n", dv->devname); rv |= 1; continue; @@ -1326,11 +1324,11 @@ int main(int argc, char *argv[]) } } else { if (update) { - fprintf(stderr, Name ": --update not meaningful with a --scan assembly.\n"); + pr_err("--update not meaningful with a --scan assembly.\n"); exit(1); } if (backup_file) { - fprintf(stderr, Name ": --backup_file not meaningful with a --scan assembly.\n"); + pr_err("--backup_file not meaningful with a --scan assembly.\n"); exit(1); } rv = scan_assemble(autof, ss, readonly, runstop, @@ -1344,19 +1342,19 @@ int main(int argc, char *argv[]) case BUILD: if (delay == 0) delay = DEFAULT_BITMAP_DELAY; if (write_behind && !bitmap_file) { - fprintf(stderr, Name ": write-behind mode requires a bitmap.\n"); + pr_err("write-behind mode requires a bitmap.\n"); rv = 1; break; } if (raiddisks == 0) { - fprintf(stderr, Name ": no raid-devices specified.\n"); + pr_err("no raid-devices specified.\n"); rv = 1; break; } if (bitmap_file) { if (strcmp(bitmap_file, "internal")==0) { - fprintf(stderr, Name ": 'internal' bitmaps not supported with --build\n"); + pr_err("'internal' bitmaps not supported with --build\n"); rv |= 1; break; } @@ -1369,12 +1367,12 @@ int main(int argc, char *argv[]) case CREATE: if (delay == 0) delay = DEFAULT_BITMAP_DELAY; if (write_behind && !bitmap_file) { - fprintf(stderr, Name ": write-behind mode requires a bitmap.\n"); + pr_err("write-behind mode requires a bitmap.\n"); rv = 1; break; } if (raiddisks == 0) { - fprintf(stderr, Name ": no raid-devices specified.\n"); + pr_err("no raid-devices specified.\n"); rv = 1; break; } @@ -1388,13 +1386,13 @@ int main(int argc, char *argv[]) case MISC: if (devmode == 'E') { if (devlist == NULL && !scan) { - fprintf(stderr, Name ": No devices to examine\n"); + pr_err("No devices to examine\n"); exit(2); } if (devlist == NULL) devlist = conf_get_devs(); if (devlist == NULL) { - fprintf(stderr, Name ": No devices listed in %s\n", configfile?configfile:DefaultConfFile); + pr_err("No devices listed in %s\n", configfile?configfile:DefaultConfFile); exit(1); } if (brief && verbose) @@ -1413,7 +1411,7 @@ int main(int argc, char *argv[]) else if (devmode == UdevRules) rv = Write_rules(udev_filename); else { - fprintf(stderr, Name ": No devices given.\n"); + pr_err("No devices given.\n"); exit(2); } } else @@ -1424,12 +1422,12 @@ int main(int argc, char *argv[]) break; case MONITOR: if (!devlist && !scan) { - fprintf(stderr, Name ": Cannot monitor: need --scan or at least one device\n"); + pr_err("Cannot monitor: need --scan or at least one device\n"); rv = 1; break; } if (pidfile && !daemonise) { - fprintf(stderr, Name ": Cannot write a pid file when not in daemon mode\n"); + pr_err("Cannot write a pid file when not in daemon mode\n"); rv = 1; break; } @@ -1456,7 +1454,7 @@ int main(int argc, char *argv[]) struct mdinfo sra; int err; if (raiddisks || level != UnSet) { - fprintf(stderr, Name ": cannot change array size in same operation " + pr_err("cannot change array size in same operation " "as changing raiddisks or level.\n" " Change size first, then check that data is still intact.\n"); rv = 1; @@ -1469,10 +1467,10 @@ int main(int argc, char *argv[]) err = sysfs_set_num(&sra, NULL, "array_size", array_size / 2); if (err < 0) { if (errno == E2BIG) - fprintf(stderr, Name ": --array-size setting" + pr_err("--array-size setting" " is too large.\n"); else - fprintf(stderr, Name ": current kernel does" + pr_err("current kernel does" " not support setting --array-size\n"); rv = 1; break; @@ -1481,7 +1479,7 @@ int main(int argc, char *argv[]) if (devs_found > 1 && raiddisks == 0) { /* must be '-a'. */ if (size >= 0 || chunk || layout_str != NULL || bitmap_file) { - fprintf(stderr, Name ": --add cannot be used with " + pr_err("--add cannot be used with " "other geometry changes in --grow mode\n"); rv = 1; break; @@ -1495,7 +1493,7 @@ int main(int argc, char *argv[]) } else if (bitmap_file) { if (size >= 0 || raiddisks || chunk || layout_str != NULL || devs_found > 1) { - fprintf(stderr, Name ": --bitmap changes cannot be " + pr_err("--bitmap changes cannot be " "used with other geometry changes " "in --grow mode\n"); rv = 1; @@ -1516,7 +1514,7 @@ int main(int argc, char *argv[]) devlist->next, assume_clean, force); } else if (array_size < 0) - fprintf(stderr, Name ": no changes to --grow\n"); + pr_err("no changes to --grow\n"); break; case INCREMENTAL: if (rebuild_map) { @@ -1524,28 +1522,24 @@ int main(int argc, char *argv[]) } if (scan) { if (runstop <= 0) { - fprintf(stderr, Name - ": --incremental --scan meaningless without --run.\n"); + pr_err("--incremental --scan meaningless without --run.\n"); break; } if (devmode == 'f') { - fprintf(stderr, Name - ": --incremental --scan --fail not supported.\n"); + pr_err("--incremental --scan --fail not supported.\n"); break; } rv = IncrementalScan(verbose); } if (!devlist) { if (!rebuild_map && !scan) { - fprintf(stderr, Name - ": --incremental requires a device.\n"); + pr_err("--incremental requires a device.\n"); rv = 1; } break; } if (devlist->next) { - fprintf(stderr, Name - ": --incremental can only handle one device.\n"); + pr_err("--incremental can only handle one device.\n"); rv = 1; break; } @@ -1580,13 +1574,12 @@ static int scan_assemble(int autof, struct supertype *ss, int failures, successes; if (conf_verify_devnames(array_list)) { - fprintf(stderr, Name - ": Duplicate MD device names in " - "conf file were found.\n"); + pr_err("Duplicate MD device names in " + "conf file were found.\n"); return 1; } if (devlist == NULL) { - fprintf(stderr, Name ": No devices listed in conf file were found.\n"); + pr_err("No devices listed in conf file were found.\n"); return 1; } for (a = array_list; a ; a = a->next) { @@ -1595,9 +1588,9 @@ static int scan_assemble(int autof, struct supertype *ss, a->autof = autof; } if (map_lock(&map)) - fprintf(stderr, Name " %s: failed to get " - "exclusive lock on mapfile\n", - __func__); + pr_err("%s: failed to get " + "exclusive lock on mapfile\n", + __func__); do { failures = 0; successes = 0; @@ -1656,12 +1649,12 @@ static int scan_assemble(int autof, struct supertype *ss, /* Incase there are stacked devices, we need to go around again */ } while (acnt); if (cnt == 0 && rv == 0) { - fprintf(stderr, Name ": No arrays found in config file or automatically\n"); + pr_err("No arrays found in config file or automatically\n"); rv = 1; } else if (cnt) rv = 0; } else if (cnt == 0 && rv == 0) { - fprintf(stderr, Name ": No arrays found in config file\n"); + pr_err("No arrays found in config file\n"); rv = 1; } map_unlock(&map); @@ -1698,7 +1691,7 @@ static int misc_scan(char devmode, int verbose, int export, int test, name = get_md_name(e->devnum); if (!name) { - fprintf(stderr, Name ": cannot find device file for %s\n", + pr_err("cannot find device file for %s\n", e->dev); continue; } @@ -1735,7 +1728,7 @@ static int stop_scan(int quiet) int mdfd; if (!name) { - fprintf(stderr, Name ": cannot find device file for %s\n", + pr_err("cannot find device file for %s\n", e->dev); continue; } @@ -1801,8 +1794,7 @@ static int misc_list(struct mddev_dev *devlist, continue; case UpdateSubarray: if (update == NULL) { - fprintf(stderr, - Name ": -U/--update must be specified with --update-subarray\n"); + pr_err("-U/--update must be specified with --update-subarray\n"); rv |= 1; continue; } diff --git a/mdadm.h b/mdadm.h index 98ea472d..e92b7686 100644 --- a/mdadm.h +++ b/mdadm.h @@ -1310,6 +1310,9 @@ static inline int xasprintf(char **strp, const char *fmt, ...) { return ret; } +#define pr_err(fmt ...) fprintf(stderr, Name ": " fmt) +#define cont_err(fmt ...) fprintf(stderr, " " fmt) + #define LEVEL_MULTIPATH (-4) #define LEVEL_LINEAR (-1) #define LEVEL_FAULTY (-5) diff --git a/mdassemble.c b/mdassemble.c index f5bc7464..f3b01202 100644 --- a/mdassemble.c +++ b/mdassemble.c @@ -32,10 +32,10 @@ int open_mddev(char *dev, int report_errors/*unused*/) { int mdfd = open(dev, O_RDWR); if (mdfd < 0) - fprintf(stderr, Name ": error opening %s: %s\n", + pr_err("error opening %s: %s\n", dev, strerror(errno)); else if (md_get_version(mdfd) <= 0) { - fprintf(stderr, Name ": %s does not appear to be an md device\n", + pr_err("%s does not appear to be an md device\n", dev); close(mdfd); mdfd = -1; @@ -68,7 +68,7 @@ int force = 0; int main(int argc, char *argv[]) { struct mddev_ident *array_list = conf_get_ident(NULL); if (!array_list) { - fprintf(stderr, Name ": No arrays found in config file\n"); + pr_err("No arrays found in config file\n"); rv = 1; } else for (; array_list; array_list = array_list->next) { diff --git a/mdopen.c b/mdopen.c index fdae7f3e..5a096aaa 100644 --- a/mdopen.c +++ b/mdopen.c @@ -175,7 +175,7 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy, /* name *must* be mdXX or md_dXX in this context */ if (num < 0 || (strcmp(cname, "md") != 0 && strcmp(cname, "md_d") != 0)) { - fprintf(stderr, Name ": %s is an invalid name " + pr_err("%s is an invalid name " "for an md device. Try /dev/md/%s\n", dev, dev+5); return -1; @@ -193,12 +193,12 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy, * empty. */ if (strchr(cname, '/') != NULL) { - fprintf(stderr, Name ": %s is an invalid name " + pr_err("%s is an invalid name " "for an md device.\n", dev); return -1; } if (cname[0] == 0) { - fprintf(stderr, Name ": %s is an invalid name " + pr_err("%s is an invalid name " "for an md device (empty!).", dev); return -1; } @@ -225,7 +225,7 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy, if (name && name[0] == 0) name = NULL; if (name && trustworthy == METADATA && use_mdp == 1) { - fprintf(stderr, Name ": %s is not allowed for a %s container. " + pr_err("%s is not allowed for a %s container. " "Consider /dev/md%d.\n", dev, name, num); return -1; } @@ -260,13 +260,13 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy, /* need to choose a free number. */ num = find_free_devnum(use_mdp); if (num == NoMdDev) { - fprintf(stderr, Name ": No avail md devices - aborting\n"); + pr_err("No avail md devices - aborting\n"); return -1; } } else { num = use_mdp ? (-1-num) : num; if (mddev_busy(num)) { - fprintf(stderr, Name ": %s is already in use.\n", + pr_err("%s is already in use.\n", dev); return -1; } @@ -328,14 +328,14 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy, /* Must be the correct device, else error */ if ((stb.st_mode&S_IFMT) != S_IFBLK || stb.st_rdev != makedev(dev2major(num),dev2minor(num))) { - fprintf(stderr, Name ": %s exists but looks wrong, please fix\n", + pr_err("%s exists but looks wrong, please fix\n", devname); return -1; } } else { if (mknod(devname, S_IFBLK|0600, makedev(dev2major(num),dev2minor(num))) != 0) { - fprintf(stderr, Name ": failed to create %s\n", + pr_err("failed to create %s\n", devname); return -1; } @@ -370,12 +370,12 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy, if ((stb.st_mode & S_IFMT) != S_IFLNK || link_len < 0 || strcmp(buf, devname) != 0) { - fprintf(stderr, Name ": %s exists - ignoring\n", + pr_err("%s exists - ignoring\n", chosen); strcpy(chosen, devname); } } else if (symlink(devname, chosen) != 0) - fprintf(stderr, Name ": failed to create %s: %s\n", + pr_err("failed to create %s: %s\n", chosen, strerror(errno)); if (use_mdp && strcmp(chosen, devname) != 0) make_parts(chosen, parts); @@ -383,7 +383,7 @@ int create_mddev(char *dev, char *name, int autof, int trustworthy, } mdfd = open_dev_excl(num); if (mdfd < 0) - fprintf(stderr, Name ": unexpected failure opening %s\n", + pr_err("unexpected failure opening %s\n", devname); return mdfd; } @@ -401,14 +401,14 @@ int open_mddev(char *dev, int report_errors) mdfd = open(dev, O_RDONLY); if (mdfd < 0) { if (report_errors) - fprintf(stderr, Name ": error opening %s: %s\n", + pr_err("error opening %s: %s\n", dev, strerror(errno)); return -1; } if (md_get_version(mdfd) <= 0) { close(mdfd); if (report_errors) - fprintf(stderr, Name ": %s does not appear to be " + pr_err("%s does not appear to be " "an md device\n", dev); return -2; } diff --git a/mdstat.c b/mdstat.c index 17405601..0dece0aa 100644 --- a/mdstat.c +++ b/mdstat.c @@ -173,13 +173,13 @@ struct mdstat_ent *mdstat_read(int hold, int start) else continue; if (ep == NULL || *ep ) { - /* fprintf(stderr, Name ": bad /proc/mdstat line starts: %s\n", line); */ + /* pr_err("bad /proc/mdstat line starts: %s\n", line); */ continue; } ent = malloc(sizeof(*ent)); if (!ent) { - fprintf(stderr, Name ": malloc failed reading /proc/mdstat.\n"); + pr_err("malloc failed reading /proc/mdstat.\n"); free_line(line); break; } diff --git a/msg.c b/msg.c index 44aad1f6..e531ef7c 100644 --- a/msg.c +++ b/msg.c @@ -310,9 +310,8 @@ int check_mdmon_version(char *container) ver = version ? mdadm_version(version) : -1; free(version); if (ver < 3002000) { - fprintf(stderr, Name - ": mdmon instance for %s cannot be disabled\n", - container); + pr_err("mdmon instance for %s cannot be disabled\n", + container); return -1; } } @@ -351,8 +350,7 @@ int block_monitor(char *container, const int freeze) ent = mdstat_read(0, 0); if (!ent) { - fprintf(stderr, Name - ": failed to read /proc/mdstat while disabling mdmon\n"); + pr_err("failed to read /proc/mdstat while disabling mdmon\n"); return -1; } @@ -363,9 +361,8 @@ int block_monitor(char *container, const int freeze) sysfs_free(sra); sra = sysfs_read(-1, e->devnum, GET_VERSION); if (!sra) { - fprintf(stderr, Name - ": failed to read sysfs for subarray%s\n", - to_subarray(e, container)); + pr_err("failed to read sysfs for subarray%s\n", + to_subarray(e, container)); break; } /* can't reshape an array that we can't monitor */ @@ -406,7 +403,7 @@ int block_monitor(char *container, const int freeze) } if (e) { - fprintf(stderr, Name ": failed to freeze subarray%s\n", + pr_err("failed to freeze subarray%s\n", to_subarray(e, container)); /* thaw the partially frozen container */ @@ -416,7 +413,7 @@ int block_monitor(char *container, const int freeze) sysfs_free(sra); sra = sysfs_read(-1, e2->devnum, GET_VERSION); if (unblock_subarray(sra, freeze)) - fprintf(stderr, Name ": Failed to unfreeze %s\n", e2->dev); + pr_err("Failed to unfreeze %s\n", e2->dev); } ping_monitor(container); /* cleared frozen */ @@ -437,8 +434,7 @@ void unblock_monitor(char *container, const int unfreeze) ent = mdstat_read(0, 0); if (!ent) { - fprintf(stderr, Name - ": failed to read /proc/mdstat while unblocking container\n"); + pr_err("failed to read /proc/mdstat while unblocking container\n"); return; } @@ -453,7 +449,7 @@ void unblock_monitor(char *container, const int unfreeze) if (sra->array.level > 0) to_ping++; if (unblock_subarray(sra, unfreeze)) - fprintf(stderr, Name ": Failed to unfreeze %s\n", e->dev); + pr_err("Failed to unfreeze %s\n", e->dev); } if (to_ping) ping_monitor(container); diff --git a/policy.c b/policy.c index cd260c69..02f70fe0 100644 --- a/policy.c +++ b/policy.c @@ -67,7 +67,7 @@ static void pol_new(struct dev_policy **pol, char *name, const char *val, if (!real_metadata) { static const char *prev = NULL; if (prev != metadata) { - fprintf(stderr, Name ": metadata=%s unrecognised - ignoring rule\n", + pr_err("metadata=%s unrecognised - ignoring rule\n", metadata); prev = metadata; } @@ -479,7 +479,7 @@ void policyline(char *line, char *type) ! try_rule(w, pol_act, &pr->rule) && ! try_rule(w, pol_domain, &pr->rule) && ! try_rule(w, pol_auto, &pr->rule)) - fprintf(stderr, Name ": policy rule %s unrecognised and ignored\n", + pr_err("policy rule %s unrecognised and ignored\n", w); } pr->next = config_rules; @@ -731,7 +731,7 @@ void policy_save_path(char *id_path, struct map_ent *array) FILE *f = NULL; if (mkdir(FAILED_SLOTS_DIR, S_IRWXU) < 0 && errno != EEXIST) { - fprintf(stderr, Name ": can't create file to save path " + pr_err("can't create file to save path " "to old disk: %s\n", strerror(errno)); return; } @@ -739,7 +739,7 @@ void policy_save_path(char *id_path, struct map_ent *array) snprintf(path, PATH_MAX, FAILED_SLOTS_DIR "/%s", id_path); f = fopen(path, "w"); if (!f) { - fprintf(stderr, Name ": can't create file to" + pr_err("can't create file to" " save path to old disk: %s\n", strerror(errno)); return; @@ -749,8 +749,8 @@ void policy_save_path(char *id_path, struct map_ent *array) array->metadata, array->uuid[0], array->uuid[1], array->uuid[2], array->uuid[3]) <= 0) - fprintf(stderr, Name ": Failed to write to " - " cookie\n"); + pr_err("Failed to write to " + " cookie\n"); fclose(f); } diff --git a/raid6check.c b/raid6check.c index d4b60859..1d91c96a 100644 --- a/raid6check.c +++ b/raid6check.c @@ -263,7 +263,7 @@ int main(int argc, char *argv[]) mdfd = open(argv[1], O_RDONLY); if(mdfd < 0) { perror(argv[1]); - fprintf(stderr,"%s: cannot open %s\n", prg, argv[1]); + fprintf(stderr, "%s: cannot open %s\n", prg, argv[1]); exit_err = 2; goto exitHere; } diff --git a/super-ddf.c b/super-ddf.c index 5e51c4cd..e8ea7e3a 100644 --- a/super-ddf.c +++ b/super-ddf.c @@ -543,34 +543,32 @@ static int load_ddf_headers(int fd, struct ddf_super *super, char *devname) if (lseek64(fd, dsize-512, 0) < 0) { if (devname) - fprintf(stderr, - Name": Cannot seek to anchor block on %s: %s\n", - devname, strerror(errno)); + pr_err("Cannot seek to anchor block on %s: %s\n", + devname, strerror(errno)); return 1; } if (read(fd, &super->anchor, 512) != 512) { if (devname) - fprintf(stderr, - Name ": Cannot read anchor block on %s: %s\n", - devname, strerror(errno)); + pr_err("Cannot read anchor block on %s: %s\n", + devname, strerror(errno)); return 1; } if (super->anchor.magic != DDF_HEADER_MAGIC) { if (devname) - fprintf(stderr, Name ": no DDF anchor found on %s\n", + pr_err("no DDF anchor found on %s\n", devname); return 2; } if (calc_crc(&super->anchor, 512) != super->anchor.crc) { if (devname) - fprintf(stderr, Name ": bad CRC on anchor on %s\n", + pr_err("bad CRC on anchor on %s\n", devname); return 2; } if (memcmp(super->anchor.revision, DDF_REVISION_0, 8) != 0 && memcmp(super->anchor.revision, DDF_REVISION_2, 8) != 0) { if (devname) - fprintf(stderr, Name ": can only support super revision" + pr_err("can only support super revision" " %.8s and earlier, not %.8s on %s\n", DDF_REVISION_2, super->anchor.revision,devname); return 2; @@ -579,9 +577,8 @@ static int load_ddf_headers(int fd, struct ddf_super *super, char *devname) dsize >> 9, 1, &super->primary, &super->anchor) == 0) { if (devname) - fprintf(stderr, - Name ": Failed to load primary DDF header " - "on %s\n", devname); + pr_err("Failed to load primary DDF header " + "on %s\n", devname); return 2; } super->active = &super->primary; @@ -652,7 +649,7 @@ static int load_ddf_local(int fd, struct ddf_super *super, if (posix_memalign((void**)&dl, 512, sizeof(*dl) + (super->max_part) * sizeof(dl->vlist[0])) != 0) { - fprintf(stderr, Name ": %s could not allocate disk info buffer\n", + pr_err("%s could not allocate disk info buffer\n", __func__); return 1; } @@ -706,9 +703,8 @@ static int load_ddf_local(int fd, struct ddf_super *super, continue; if (posix_memalign((void**)&dl->spare, 512, super->conf_rec_len*512) != 0) { - fprintf(stderr, Name - ": %s could not allocate spare info buf\n", - __func__); + pr_err("%s could not allocate spare info buf\n", + __func__); return 1; } @@ -732,9 +728,8 @@ static int load_ddf_local(int fd, struct ddf_super *super, if (posix_memalign((void**)&vcl, 512, (super->conf_rec_len*512 + offsetof(struct vcl, conf))) != 0) { - fprintf(stderr, Name - ": %s could not allocate vcl buf\n", - __func__); + pr_err("%s could not allocate vcl buf\n", + __func__); return 1; } vcl->next = super->conflist; @@ -782,25 +777,23 @@ static int load_super_ddf(struct supertype *st, int fd, /* 32M is a lower bound */ if (dsize <= 32*1024*1024) { if (devname) - fprintf(stderr, - Name ": %s is too small for ddf: " - "size is %llu sectors.\n", - devname, dsize>>9); + pr_err("%s is too small for ddf: " + "size is %llu sectors.\n", + devname, dsize>>9); return 1; } if (dsize & 511) { if (devname) - fprintf(stderr, - Name ": %s is an odd size for ddf: " - "size is %llu bytes.\n", - devname, dsize); + pr_err("%s is an odd size for ddf: " + "size is %llu bytes.\n", + devname, dsize); return 1; } free_super_ddf(st); if (posix_memalign((void**)&super, 512, sizeof(*super))!= 0) { - fprintf(stderr, Name ": malloc of %zu failed.\n", + pr_err("malloc of %zu failed.\n", sizeof(*super)); return 1; } @@ -818,9 +811,8 @@ static int load_super_ddf(struct supertype *st, int fd, if (rv) { if (devname) - fprintf(stderr, - Name ": Failed to load all information " - "sections on %s\n", devname); + pr_err("Failed to load all information " + "sections on %s\n", devname); free(super); return rv; } @@ -829,9 +821,8 @@ static int load_super_ddf(struct supertype *st, int fd, if (rv) { if (devname) - fprintf(stderr, - Name ": Failed to load all information " - "sections on %s\n", devname); + pr_err("Failed to load all information " + "sections on %s\n", devname); free(super); return rv; } @@ -1629,7 +1620,7 @@ static int init_super_ddf(struct supertype *st, return init_super_ddf_bvd(st, info, size, name, homehost, uuid); if (posix_memalign((void**)&ddf, 512, sizeof(*ddf)) != 0) { - fprintf(stderr, Name ": %s could not allocate superblock\n", __func__); + pr_err("%s could not allocate superblock\n", __func__); return 0; } memset(ddf, 0, sizeof(*ddf)); @@ -1767,7 +1758,7 @@ static int init_super_ddf(struct supertype *st, strcpy((char*)ddf->controller.vendor_data, homehost); if (posix_memalign((void**)&pd, 512, pdsize) != 0) { - fprintf(stderr, Name ": %s could not allocate pd\n", __func__); + pr_err("%s could not allocate pd\n", __func__); return 0; } ddf->phys = pd; @@ -1781,7 +1772,7 @@ static int init_super_ddf(struct supertype *st, memset(pd->pad, 0xff, 52); if (posix_memalign((void**)&vd, 512, vdsize) != 0) { - fprintf(stderr, Name ": %s could not allocate vd\n", __func__); + pr_err("%s could not allocate vd\n", __func__); return 0; } ddf->virt = vd; @@ -1970,9 +1961,9 @@ static int init_super_ddf_bvd(struct supertype *st, if (__be16_to_cpu(ddf->virt->populated_vdes) >= __be16_to_cpu(ddf->virt->max_vdes)) { - fprintf(stderr, Name": This ddf already has the " - "maximum of %d virtual devices\n", - __be16_to_cpu(ddf->virt->max_vdes)); + pr_err("This ddf already has the " + "maximum of %d virtual devices\n", + __be16_to_cpu(ddf->virt->max_vdes)); return 0; } @@ -1982,9 +1973,9 @@ static int init_super_ddf_bvd(struct supertype *st, char *n = ddf->virt->entries[venum].name; if (strncmp(name, n, 16) == 0) { - fprintf(stderr, Name ": This ddf already" - " has an array called %s\n", - name); + pr_err("This ddf already" + " has an array called %s\n", + name); return 0; } } @@ -1993,7 +1984,7 @@ static int init_super_ddf_bvd(struct supertype *st, if (all_ff(ddf->virt->entries[venum].guid)) break; if (venum == __be16_to_cpu(ddf->virt->max_vdes)) { - fprintf(stderr, Name ": Cannot find spare slot for " + pr_err("Cannot find spare slot for " "virtual disk - DDF is corrupt\n"); return 0; } @@ -2023,7 +2014,7 @@ static int init_super_ddf_bvd(struct supertype *st, /* Now create a new vd_config */ if (posix_memalign((void**)&vcl, 512, (offsetof(struct vcl, conf) + ddf->conf_rec_len * 512)) != 0) { - fprintf(stderr, Name ": %s could not allocate vd_config\n", __func__); + pr_err("%s could not allocate vd_config\n", __func__); return 0; } vcl->lba_offset = (__u64*) &vcl->conf.phys_refnum[ddf->mppe]; @@ -2208,9 +2199,8 @@ static int add_to_super_ddf(struct supertype *st, fstat(fd, &stb); if (posix_memalign((void**)&dd, 512, sizeof(*dd) + sizeof(dd->vlist[0]) * ddf->max_part) != 0) { - fprintf(stderr, Name - ": %s could allocate buffer for new disk, aborting\n", - __func__); + pr_err("%s could allocate buffer for new disk, aborting\n", + __func__); return 1; } dd->major = major(stb.st_rdev); @@ -2554,7 +2544,7 @@ static int reserve_space(struct supertype *st, int raiddisks, free(e); } if (cnt < raiddisks) { - fprintf(stderr, Name ": not enough devices with space to create array.\n"); + pr_err("not enough devices with space to create array.\n"); return 0; /* No enough free spaces large enough */ } if (size == 0) { @@ -2577,7 +2567,7 @@ static int reserve_space(struct supertype *st, int raiddisks, } *freesize = size; if (size < 32) { - fprintf(stderr, Name ": not enough spare devices to create array.\n"); + pr_err("not enough spare devices to create array.\n"); return 0; } } @@ -2646,7 +2636,7 @@ static int validate_geometry_ddf(struct supertype *st, break; if (ddf_level_num[i].num1 == MAXINT) { if (verbose) - fprintf(stderr, Name ": DDF does not support level %d arrays\n", + pr_err("DDF does not support level %d arrays\n", level); return 0; } @@ -2695,15 +2685,14 @@ static int validate_geometry_ddf(struct supertype *st, } if (verbose) - fprintf(stderr, - Name ": ddf: Cannot create this array " - "on device %s - a container is required.\n", - dev); + pr_err("ddf: Cannot create this array " + "on device %s - a container is required.\n", + dev); return 0; } if (errno != EBUSY || (fd = open(dev, O_RDONLY, 0)) < 0) { if (verbose) - fprintf(stderr, Name ": ddf: Cannot open %s: %s\n", + pr_err("ddf: Cannot open %s: %s\n", dev, strerror(errno)); return 0; } @@ -2712,7 +2701,7 @@ static int validate_geometry_ddf(struct supertype *st, if (cfd < 0) { close(fd); if (verbose) - fprintf(stderr, Name ": ddf: Cannot use %s: %s\n", + pr_err("ddf: Cannot use %s: %s\n", dev, strerror(EBUSY)); return 0; } @@ -2758,7 +2747,7 @@ validate_geometry_ddf_container(struct supertype *st, fd = open(dev, O_RDONLY|O_EXCL, 0); if (fd < 0) { if (verbose) - fprintf(stderr, Name ": ddf: Cannot open %s: %s\n", + pr_err("ddf: Cannot open %s: %s\n", dev, strerror(errno)); return 0; } @@ -2791,7 +2780,7 @@ static int validate_geometry_ddf_bvd(struct supertype *st, /* ddf/bvd supports lots of things, but not containers */ if (level == LEVEL_CONTAINER) { if (verbose) - fprintf(stderr, Name ": DDF cannot create a container within an container\n"); + pr_err("DDF cannot create a container within an container\n"); return 0; } /* We must have the container info already read in. */ @@ -2828,10 +2817,9 @@ static int validate_geometry_ddf_bvd(struct supertype *st, } if (dcnt < raiddisks) { if (verbose) - fprintf(stderr, - Name ": ddf: Not enough devices with " - "space for this array (%d < %d)\n", - dcnt, raiddisks); + pr_err("ddf: Not enough devices with " + "space for this array (%d < %d)\n", + dcnt, raiddisks); return 0; } return 1; @@ -2848,7 +2836,7 @@ static int validate_geometry_ddf_bvd(struct supertype *st, } if (!dl) { if (verbose) - fprintf(stderr, Name ": ddf: %s is not in the " + pr_err("ddf: %s is not in the " "same DDF set\n", dev); return 0; diff --git a/super-gpt.c b/super-gpt.c index 75269bf1..9360aead 100644 --- a/super-gpt.c +++ b/super-gpt.c @@ -77,7 +77,7 @@ static int load_gpt(struct supertype *st, int fd, char *devname) free_gpt(st); if (posix_memalign((void**)&super, 4096, 32*512) != 0) { - fprintf(stderr, Name ": %s could not allocate superblock\n", + pr_err("%s could not allocate superblock\n", __func__); return 1; } @@ -88,7 +88,7 @@ static int load_gpt(struct supertype *st, int fd, char *devname) if (read(fd, super, sizeof(*super)) != sizeof(*super)) { no_read: if (devname) - fprintf(stderr, Name ": Cannot read partition table on %s\n", + pr_err("Cannot read partition table on %s\n", devname); free(super); return 1; @@ -98,7 +98,7 @@ static int load_gpt(struct supertype *st, int fd, char *devname) super->parts[0].part_type != MBR_GPT_PARTITION_TYPE) { not_found: if (devname) - fprintf(stderr, Name ": No partition table found on %s\n", + pr_err("No partition table found on %s\n", devname); free(super); return 1; @@ -199,7 +199,7 @@ static int validate_geometry(struct supertype *st, int level, char *subdev, unsigned long long *freesize, int verbose) { - fprintf(stderr, Name ": gpt metadata cannot be used this way\n"); + pr_err("gpt metadata cannot be used this way\n"); return 0; } #endif diff --git a/super-intel.c b/super-intel.c index 07ab9aed..2ecb9589 100644 --- a/super-intel.c +++ b/super-intel.c @@ -295,7 +295,7 @@ struct md_list { struct md_list *next; }; -#define pr_vrb(fmt, arg...) (void) (verbose && fprintf(stderr, Name fmt, ##arg)) +#define pr_vrb(fmt, arg...) (void) (verbose && pr_err(fmt, ##arg)) static __u8 migr_type(struct imsm_dev *dev) { @@ -1341,7 +1341,7 @@ static int imsm_check_attributes(__u32 attributes) not_supported &= attributes; if (not_supported) { - fprintf(stderr, Name "(IMSM): Unsupported attributes : %x\n", + pr_err("(IMSM): Unsupported attributes : %x\n", (unsigned)__le32_to_cpu(not_supported)); if (not_supported & MPB_ATTRIB_CHECKSUM_VERIFY) { dprintf("\t\tMPB_ATTRIB_CHECKSUM_VERIFY \n"); @@ -1573,7 +1573,7 @@ static int ahci_enumerate_ports(const char *hba_path, int port_count, int host_b if (port_count > (int)sizeof(port_mask) * 8) { if (verbose) - fprintf(stderr, Name ": port_count %d out of range\n", port_count); + pr_err("port_count %d out of range\n", port_count); return 2; } @@ -1606,14 +1606,14 @@ static int ahci_enumerate_ports(const char *hba_path, int port_count, int host_b /* retrieve the scsi device type */ if (asprintf(&device, "/sys/dev/block/%d:%d/device/xxxxxxx", major, minor) < 0) { if (verbose) - fprintf(stderr, Name ": failed to allocate 'device'\n"); + pr_err("failed to allocate 'device'\n"); err = 2; break; } sprintf(device, "/sys/dev/block/%d:%d/device/type", major, minor); if (load_sys(device, buf) != 0) { if (verbose) - fprintf(stderr, Name ": failed to read device type for %s\n", + pr_err("failed to read device type for %s\n", path); err = 2; free(device); @@ -1666,7 +1666,7 @@ static int ahci_enumerate_ports(const char *hba_path, int port_count, int host_b c = strchr(&path[hba_len], '/'); if (!c) { if (verbose) - fprintf(stderr, Name ": %s - invalid path name\n", path + hba_len); + pr_err("%s - invalid path name\n", path + hba_len); err = 2; break; } @@ -1676,7 +1676,7 @@ static int ahci_enumerate_ports(const char *hba_path, int port_count, int host_b else { if (verbose) { *c = '/'; /* repair the full string */ - fprintf(stderr, Name ": failed to determine port number for %s\n", + pr_err("failed to determine port number for %s\n", path); } err = 2; @@ -1725,7 +1725,7 @@ static int ahci_enumerate_ports(const char *hba_path, int port_count, int host_b static void print_found_intel_controllers(struct sys_dev *elem) { for (; elem; elem = elem->next) { - fprintf(stderr, Name ": found Intel(R) "); + pr_err("found Intel(R) "); if (elem->type == SYS_DEV_SATA) fprintf(stderr, "SATA "); else if (elem->type == SYS_DEV_SAS) @@ -1842,7 +1842,7 @@ static int detail_platform_imsm(int verbose, int enumerate_only) list = find_intel_devices(); if (!list) { if (verbose) - fprintf(stderr, Name ": no active Intel(R) RAID " + pr_err("no active Intel(R) RAID " "controller found.\n"); free_sys_dev(&list); return 2; @@ -1852,7 +1852,7 @@ static int detail_platform_imsm(int verbose, int enumerate_only) for (hba = list; hba; hba = hba->next) { orom = find_imsm_capability(hba->type); if (!orom) - fprintf(stderr, Name ": imsm capabilities not found for controller: %s (type %s)\n", + pr_err("imsm capabilities not found for controller: %s (type %s)\n", hba->path, get_sys_dev_type(hba->type)); else print_imsm_capability(orom); @@ -1866,7 +1866,7 @@ static int detail_platform_imsm(int verbose, int enumerate_only) host_base = ahci_get_port_count(hba->path, &port_count); if (ahci_enumerate_ports(hba->path, port_count, host_base, verbose)) { if (verbose) - fprintf(stderr, Name ": failed to enumerate " + pr_err("failed to enumerate " "ports on SATA controller at %s.", hba->pci_id); result |= 2; } @@ -2183,16 +2183,14 @@ static int read_imsm_migr_rec(int fd, struct intel_super *super) get_dev_size(fd, NULL, &dsize); if (lseek64(fd, dsize - MIGR_REC_POSITION, SEEK_SET) < 0) { - fprintf(stderr, - Name ": Cannot seek to anchor block: %s\n", - strerror(errno)); + pr_err("Cannot seek to anchor block: %s\n", + strerror(errno)); goto out; } if (read(fd, super->migr_rec_buf, MIGR_REC_BUF_SIZE) != MIGR_REC_BUF_SIZE) { - fprintf(stderr, - Name ": Cannot read migr record block: %s\n", - strerror(errno)); + pr_err("Cannot read migr record block: %s\n", + strerror(errno)); goto out; } ret_val = 0; @@ -2389,16 +2387,14 @@ static int write_imsm_migr_rec(struct supertype *st) continue; get_dev_size(fd, NULL, &dsize); if (lseek64(fd, dsize - MIGR_REC_POSITION, SEEK_SET) < 0) { - fprintf(stderr, - Name ": Cannot seek to anchor block: %s\n", - strerror(errno)); + pr_err("Cannot seek to anchor block: %s\n", + strerror(errno)); goto out; } if (write(fd, super->migr_rec_buf, MIGR_REC_BUF_SIZE) != MIGR_REC_BUF_SIZE) { - fprintf(stderr, - Name ": Cannot write migr record block: %s\n", - strerror(errno)); + pr_err("Cannot write migr record block: %s\n", + strerror(errno)); goto out; } close(fd); @@ -2851,7 +2847,7 @@ struct mdinfo *getinfo_super_disks_imsm(struct supertype *st) dl = super->disks; mddev = malloc(sizeof(*mddev)); if (!mddev) { - fprintf(stderr, Name ": Failed to allocate memory.\n"); + pr_err("Failed to allocate memory.\n"); return NULL; } memset(mddev, 0, sizeof(*mddev)); @@ -2860,7 +2856,7 @@ struct mdinfo *getinfo_super_disks_imsm(struct supertype *st) disk = &dl->disk; tmp = malloc(sizeof(*tmp)); if (!tmp) { - fprintf(stderr, Name ": Failed to allocate memory.\n"); + pr_err("Failed to allocate memory.\n"); if (mddev) sysfs_free(mddev); return NULL; @@ -3149,18 +3145,16 @@ static int imsm_read_serial(int fd, char *devname, if (rv != 0) { if (devname) - fprintf(stderr, - Name ": Failed to retrieve serial for %s\n", - devname); + pr_err("Failed to retrieve serial for %s\n", + devname); return rv; } rsp_len = scsi_serial[3]; if (!rsp_len) { if (devname) - fprintf(stderr, - Name ": Failed to retrieve serial for %s\n", - devname); + pr_err("Failed to retrieve serial for %s\n", + devname); return 2; } rsp_buf = (char *) &scsi_serial[4]; @@ -3252,9 +3246,8 @@ load_imsm_disk(int fd, struct intel_super *super, char *devname, int keep_fd) dl = calloc(1, sizeof(*dl)); if (!dl) { if (devname) - fprintf(stderr, - Name ": failed to allocate disk buffer for %s\n", - devname); + pr_err("failed to allocate disk buffer for %s\n", + devname); return 2; } @@ -3505,40 +3498,35 @@ static int load_imsm_mpb(int fd, struct intel_super *super, char *devname) get_dev_size(fd, NULL, &dsize); if (dsize < 1024) { if (devname) - fprintf(stderr, - Name ": %s: device to small for imsm\n", - devname); + pr_err("%s: device to small for imsm\n", + devname); return 1; } if (lseek64(fd, dsize - (512 * 2), SEEK_SET) < 0) { if (devname) - fprintf(stderr, Name - ": Cannot seek to anchor block on %s: %s\n", - devname, strerror(errno)); + pr_err("Cannot seek to anchor block on %s: %s\n", + devname, strerror(errno)); return 1; } if (posix_memalign((void**)&anchor, 512, 512) != 0) { if (devname) - fprintf(stderr, - Name ": Failed to allocate imsm anchor buffer" - " on %s\n", devname); + pr_err("Failed to allocate imsm anchor buffer" + " on %s\n", devname); return 1; } if (read(fd, anchor, 512) != 512) { if (devname) - fprintf(stderr, - Name ": Cannot read anchor block on %s: %s\n", - devname, strerror(errno)); + pr_err("Cannot read anchor block on %s: %s\n", + devname, strerror(errno)); free(anchor); return 1; } if (strncmp((char *) anchor->sig, MPB_SIGNATURE, MPB_SIG_LEN) != 0) { if (devname) - fprintf(stderr, - Name ": no IMSM anchor on %s\n", devname); + pr_err("no IMSM anchor on %s\n", devname); free(anchor); return 2; } @@ -3551,9 +3539,8 @@ static int load_imsm_mpb(int fd, struct intel_super *super, char *devname) super->len = ROUND_UP(anchor->mpb_size, 512); if (posix_memalign(&super->buf, 512, super->len) != 0) { if (devname) - fprintf(stderr, - Name ": unable to allocate %zu byte mpb buffer\n", - super->len); + pr_err("unable to allocate %zu byte mpb buffer\n", + super->len); free(anchor); return 2; } @@ -3563,8 +3550,7 @@ static int load_imsm_mpb(int fd, struct intel_super *super, char *devname) free(anchor); if (posix_memalign(&super->migr_rec_buf, 512, MIGR_REC_BUF_SIZE) != 0) { - fprintf(stderr, Name - ": %s could not allocate migr_rec buffer\n", __func__); + pr_err("%s could not allocate migr_rec buffer\n", __func__); free(super->buf); return 2; } @@ -3574,11 +3560,10 @@ static int load_imsm_mpb(int fd, struct intel_super *super, char *devname) check_sum = __gen_imsm_checksum(super->anchor); if (check_sum != __le32_to_cpu(super->anchor->check_sum)) { if (devname) - fprintf(stderr, - Name ": IMSM checksum %x != %x on %s\n", - check_sum, - __le32_to_cpu(super->anchor->check_sum), - devname); + pr_err("IMSM checksum %x != %x on %s\n", + check_sum, + __le32_to_cpu(super->anchor->check_sum), + devname); return 2; } @@ -3588,27 +3573,24 @@ static int load_imsm_mpb(int fd, struct intel_super *super, char *devname) /* read the extended mpb */ if (lseek64(fd, dsize - (512 * (2 + sectors)), SEEK_SET) < 0) { if (devname) - fprintf(stderr, - Name ": Cannot seek to extended mpb on %s: %s\n", - devname, strerror(errno)); + pr_err("Cannot seek to extended mpb on %s: %s\n", + devname, strerror(errno)); return 1; } if ((unsigned)read(fd, super->buf + 512, super->len - 512) != super->len - 512) { if (devname) - fprintf(stderr, - Name ": Cannot read extended mpb on %s: %s\n", - devname, strerror(errno)); + pr_err("Cannot read extended mpb on %s: %s\n", + devname, strerror(errno)); return 2; } check_sum = __gen_imsm_checksum(super->anchor); if (check_sum != __le32_to_cpu(super->anchor->check_sum)) { if (devname) - fprintf(stderr, - Name ": IMSM checksum %x != %x on %s\n", - check_sum, __le32_to_cpu(super->anchor->check_sum), - devname); + pr_err("IMSM checksum %x != %x on %s\n", + check_sum, __le32_to_cpu(super->anchor->check_sum), + devname); return 3; } @@ -3773,9 +3755,8 @@ static int find_intel_hba_capability(int fd, struct intel_super *super, char *de hba_name = find_disk_attached_hba(fd, NULL); if (!hba_name) { if (devname) - fprintf(stderr, - Name ": %s is not attached to Intel(R) RAID controller.\n", - devname); + pr_err("%s is not attached to Intel(R) RAID controller.\n", + devname); return 1; } rv = attach_hba_to_super(super, hba_name); @@ -3783,7 +3764,7 @@ static int find_intel_hba_capability(int fd, struct intel_super *super, char *de if (devname) { struct intel_hba *hba = super->hba; - fprintf(stderr, Name ": %s is attached to Intel(R) %s RAID " + pr_err("%s is attached to Intel(R) %s RAID " "controller (%s),\n" " but the container is assigned to Intel(R) " "%s RAID controller (", @@ -4219,7 +4200,7 @@ static int load_super_imsm_all(struct supertype *st, int fd, void **sbp, /* Check migration compatibility */ if ((err == 0) && (check_mpb_migr_compatibility(super) != 0)) { - fprintf(stderr, Name ": Unsupported migration detected"); + pr_err("Unsupported migration detected"); if (devname) fprintf(stderr, " on %s\n", devname); else @@ -4272,7 +4253,7 @@ get_devlist_super_block(struct md_list *devlist, struct intel_super **super_list int lmax = 0; int fd = dev_open(tmpdev->devname, O_RDONLY|O_EXCL); if (fd < 0) { - fprintf(stderr, Name ": cannot open device %s: %s\n", + pr_err("cannot open device %s: %s\n", tmpdev->devname, strerror(errno)); err = 8; goto error; @@ -4414,9 +4395,8 @@ static int load_super_imsm(struct supertype *st, int fd, char *devname) super = alloc_super(); if (!super) { - fprintf(stderr, - Name ": malloc of %zu failed.\n", - sizeof(*super)); + pr_err("malloc of %zu failed.\n", + sizeof(*super)); return 1; } /* Load hba and capabilities if they exist. @@ -4427,8 +4407,7 @@ static int load_super_imsm(struct supertype *st, int fd, char *devname) /* no orom/efi or non-intel hba of the disk */ if ((rv != 0) && (st->ignore_hw_compat == 0)) { if (devname) - fprintf(stderr, - Name ": No OROM/EFI properties for %s\n", devname); + pr_err("No OROM/EFI properties for %s\n", devname); free_imsm(super); return 2; } @@ -4436,9 +4415,8 @@ static int load_super_imsm(struct supertype *st, int fd, char *devname) if (rv) { if (devname) - fprintf(stderr, - Name ": Failed to load all information " - "sections on %s\n", devname); + pr_err("Failed to load all information " + "sections on %s\n", devname); free_imsm(super); return rv; } @@ -4454,8 +4432,7 @@ static int load_super_imsm(struct supertype *st, int fd, char *devname) if (load_imsm_migr_rec(super, NULL) == 0) { /* Check for unsupported migration features */ if (check_mpb_migr_compatibility(super) != 0) { - fprintf(stderr, - Name ": Unsupported migration detected"); + pr_err("Unsupported migration detected"); if (devname) fprintf(stderr, " on %s\n", devname); else @@ -4549,7 +4526,7 @@ static int check_name(struct intel_super *super, char *name, int quiet) } if (reason && !quiet) - fprintf(stderr, Name ": imsm volume name %s\n", reason); + pr_err("imsm volume name %s\n", reason); return !reason; } @@ -4574,7 +4551,7 @@ static int init_super_imsm_volume(struct supertype *st, mdu_array_info_t *info, unsigned long long num_data_stripes; if (super->orom && mpb->num_raid_devs >= super->orom->vpa) { - fprintf(stderr, Name": This imsm-container already has the " + pr_err("This imsm-container already has the " "maximum of %d volumes\n", super->orom->vpa); return 0; } @@ -4587,14 +4564,13 @@ static int init_super_imsm_volume(struct supertype *st, mdu_array_info_t *info, size_t size_round = ROUND_UP(size_new, 512); if (posix_memalign(&mpb_new, 512, size_round) != 0) { - fprintf(stderr, Name": could not allocate new mpb\n"); + pr_err("could not allocate new mpb\n"); return 0; } if (posix_memalign(&super->migr_rec_buf, 512, MIGR_REC_BUF_SIZE) != 0) { - fprintf(stderr, Name - ": %s could not allocate migr_rec buffer\n", - __func__); + pr_err("%s could not allocate migr_rec buffer\n", + __func__); free(super->buf); free(super); free(mpb_new); @@ -4638,7 +4614,7 @@ static int init_super_imsm_volume(struct supertype *st, mdu_array_info_t *info, for (d = super->missing; d; d = d->next) missing++; if (info->failed_disks > missing) { - fprintf(stderr, Name": unable to add 'missing' disk to container\n"); + pr_err("unable to add 'missing' disk to container\n"); return 0; } } @@ -4647,13 +4623,13 @@ static int init_super_imsm_volume(struct supertype *st, mdu_array_info_t *info, return 0; dv = malloc(sizeof(*dv)); if (!dv) { - fprintf(stderr, Name ": failed to allocate device list entry\n"); + pr_err("failed to allocate device list entry\n"); return 0; } dev = calloc(1, sizeof(*dev) + sizeof(__u32) * (info->raid_disks - 1)); if (!dev) { free(dv); - fprintf(stderr, Name": could not allocate raid device\n"); + pr_err("could not allocate raid device\n"); return 0; } @@ -4687,7 +4663,7 @@ static int init_super_imsm_volume(struct supertype *st, mdu_array_info_t *info, if (info->level == 1 && info->raid_disks > 2) { free(dev); free(dv); - fprintf(stderr, Name": imsm does not support more than 2 disks" + pr_err("imsm does not support more than 2 disks" "in a raid1 volume\n"); return 0; } @@ -4754,13 +4730,11 @@ static int init_super_imsm(struct supertype *st, mdu_array_info_t *info, super = NULL; } if (!super) { - fprintf(stderr, Name - ": %s could not allocate superblock\n", __func__); + pr_err("%s could not allocate superblock\n", __func__); return 0; } if (posix_memalign(&super->migr_rec_buf, 512, MIGR_REC_BUF_SIZE) != 0) { - fprintf(stderr, Name - ": %s could not allocate migr_rec buffer\n", __func__); + pr_err("%s could not allocate migr_rec buffer\n", __func__); free(super->buf); free(super); return 0; @@ -4801,7 +4775,7 @@ static int add_to_super_imsm_volume(struct supertype *st, mdu_disk_info_t *dk, map = get_imsm_map(dev, MAP_0); if (! (dk->state & (1<index); if (slot >= 0 && (get_imsm_ord_tbl_ent(dev, slot, MAP_X) & IMSM_ORD_REBUILD) == 0) { - fprintf(stderr, Name ": %s has been included in this array twice\n", + pr_err("%s has been included in this array twice\n", devname); return 1; } @@ -4890,7 +4864,7 @@ static int add_to_super_imsm_volume(struct supertype *st, mdu_disk_info_t *dk, _disk = __get_imsm_disk(mpb, dl->index); if (!_dev || !_disk) { - fprintf(stderr, Name ": BUG mpb setup error\n"); + pr_err("BUG mpb setup error\n"); return 1; } *_dev = *dev; @@ -4965,8 +4939,7 @@ static int add_to_super_imsm(struct supertype *st, mdu_disk_info_t *dk, fstat(fd, &stb); dd = malloc(sizeof(*dd)); if (!dd) { - fprintf(stderr, - Name ": malloc failed %s:%d.\n", __func__, __LINE__); + pr_err("malloc failed %s:%d.\n", __func__, __LINE__); return 1; } memset(dd, 0, sizeof(*dd)); @@ -4978,8 +4951,7 @@ static int add_to_super_imsm(struct supertype *st, mdu_disk_info_t *dk, dd->action = DISK_ADD; rv = imsm_read_serial(fd, devname, dd->serial); if (rv) { - fprintf(stderr, - Name ": failed to retrieve scsi serial, aborting\n"); + pr_err("failed to retrieve scsi serial, aborting\n"); free(dd); abort(); } @@ -5021,15 +4993,13 @@ static int remove_from_super_imsm(struct supertype *st, mdu_disk_info_t *dk) * is prepared. */ if (!st->update_tail) { - fprintf(stderr, - Name ": %s shall be used in mdmon context only" - "(line %d).\n", __func__, __LINE__); + pr_err("%s shall be used in mdmon context only" + "(line %d).\n", __func__, __LINE__); return 1; } dd = malloc(sizeof(*dd)); if (!dd) { - fprintf(stderr, - Name ": malloc failed %s:%d.\n", __func__, __LINE__); + pr_err("malloc failed %s:%d.\n", __func__, __LINE__); return 1; } memset(dd, 0, sizeof(*dd)); @@ -5330,7 +5300,7 @@ static int validate_geometry_imsm_container(struct supertype *st, int level, fd = open(dev, O_RDONLY|O_EXCL, 0); if (fd < 0) { if (verbose) - fprintf(stderr, Name ": imsm: Cannot open %s: %s\n", + pr_err("imsm: Cannot open %s: %s\n", dev, strerror(errno)); return 0; } @@ -5344,9 +5314,8 @@ static int validate_geometry_imsm_container(struct supertype *st, int level, */ super = alloc_super(); if (!super) { - fprintf(stderr, - Name ": malloc of %zu failed.\n", - sizeof(*super)); + pr_err("malloc of %zu failed.\n", + sizeof(*super)); close(fd); return 0; } @@ -5368,7 +5337,7 @@ static int validate_geometry_imsm_container(struct supertype *st, int level, if (super->orom) { if (raiddisks > super->orom->tds) { if (verbose) - fprintf(stderr, Name ": %d exceeds maximum number of" + pr_err("%d exceeds maximum number of" " platform supported disks: %d\n", raiddisks, super->orom->tds); free_imsm(super); @@ -5377,7 +5346,7 @@ static int validate_geometry_imsm_container(struct supertype *st, int level, if ((super->orom->attr & IMSM_OROM_ATTR_2TB_DISK) == 0 && (ldsize >> 9) >> 32 > 0) { if (verbose) - fprintf(stderr, Name ": %s exceeds maximum platform supported size\n", dev); + pr_err("%s exceeds maximum platform supported size\n", dev); free_imsm(super); return 0; } @@ -5567,7 +5536,7 @@ active_arrays_by_format(char *name, char* hba, struct md_list **devlist, if (*devlist && (found < dpa)) { dv = calloc(1, sizeof(*dv)); if (dv == NULL) - fprintf(stderr, Name ": calloc failed\n"); + pr_err("calloc failed\n"); else { dv->devname = malloc(strlen(memb->dev) + strlen("/dev/") + 1); if (dv->devname != NULL) { @@ -5600,12 +5569,12 @@ get_loop_devices(void) for(i = 0; i < 12; i++) { dv = calloc(1, sizeof(*dv)); if (dv == NULL) { - fprintf(stderr, Name ": calloc failed\n"); + pr_err("calloc failed\n"); break; } dv->devname = malloc(40); if (dv->devname == NULL) { - fprintf(stderr, Name ": malloc failed\n"); + pr_err("malloc failed\n"); free(dv); break; } @@ -5656,7 +5625,7 @@ get_devices(const char *hba_path) fd2devname(fd, buf); close(fd); } else { - fprintf(stderr, Name ": cannot open device: %s\n", + pr_err("cannot open device: %s\n", ent->d_name); continue; } @@ -5664,13 +5633,13 @@ get_devices(const char *hba_path) dv = calloc(1, sizeof(*dv)); if (dv == NULL) { - fprintf(stderr, Name ": malloc failed\n"); + pr_err("malloc failed\n"); err = 1; break; } dv->devname = strdup(buf); if (dv->devname == NULL) { - fprintf(stderr, Name ": malloc failed\n"); + pr_err("malloc failed\n"); err = 1; free(dv); break; @@ -5972,7 +5941,7 @@ static int validate_geometry_imsm_volume(struct supertype *st, int level, mpb = super->anchor; if (!validate_geometry_imsm_orom(super, level, layout, raiddisks, chunk, size, verbose)) { - fprintf(stderr, Name ": RAID gemetry validation failed. " + pr_err("RAID gemetry validation failed. " "Cannot proceed with the action(s).\n"); return 0; } @@ -6014,7 +5983,7 @@ static int validate_geometry_imsm_volume(struct supertype *st, int level, } if (dcnt < raiddisks) { if (verbose) - fprintf(stderr, Name ": imsm: Not enough " + pr_err("imsm: Not enough " "devices with space for this array " "(%d < %d)\n", dcnt, raiddisks); @@ -6035,7 +6004,7 @@ static int validate_geometry_imsm_volume(struct supertype *st, int level, } if (!dl) { if (verbose) - fprintf(stderr, Name ": %s is not in the " + pr_err("%s is not in the " "same imsm set\n", dev); return 0; } else if (super->orom && dl->index < 0 && mpb->num_raid_devs) { @@ -6044,14 +6013,14 @@ static int validate_geometry_imsm_volume(struct supertype *st, int level, * understand this configuration (all member disks must be * members of each array in the container). */ - fprintf(stderr, Name ": %s is a spare and a volume" + pr_err("%s is a spare and a volume" " is already defined for this container\n", dev); - fprintf(stderr, Name ": The option-rom requires all member" + pr_err("The option-rom requires all member" " disks to be a member of all volumes\n"); return 0; } else if (super->orom && mpb->num_raid_devs > 0 && mpb->num_disks != raiddisks) { - fprintf(stderr, Name ": The option-rom requires all member" + pr_err("The option-rom requires all member" " disks to be a member of all volumes\n"); return 0; } @@ -6074,13 +6043,13 @@ static int validate_geometry_imsm_volume(struct supertype *st, int level, dl->extent_cnt = i; } else { if (verbose) - fprintf(stderr, Name ": unable to determine free space for: %s\n", + pr_err("unable to determine free space for: %s\n", dev); return 0; } if (maxsize < size) { if (verbose) - fprintf(stderr, Name ": %s not enough space (%llu < %llu)\n", + pr_err("%s not enough space (%llu < %llu)\n", dev, maxsize, size); return 0; } @@ -6095,7 +6064,7 @@ static int validate_geometry_imsm_volume(struct supertype *st, int level, if (!check_env("IMSM_NO_PLATFORM") && mpb->num_raid_devs > 0 && size && size != maxsize) { - fprintf(stderr, Name ": attempting to create a second " + pr_err("attempting to create a second " "volume with size less then remaining space. " "Aborting...\n"); return 0; @@ -6104,10 +6073,10 @@ static int validate_geometry_imsm_volume(struct supertype *st, int level, if (maxsize < size || maxsize == 0) { if (verbose) { if (maxsize == 0) - fprintf(stderr, Name ": no free space" + pr_err("no free space" " left on device. Aborting...\n"); else - fprintf(stderr, Name ": not enough space" + pr_err("not enough space" " to create volume of given size" " (%llu < %llu). Aborting...\n", maxsize, size); @@ -6181,7 +6150,7 @@ static int imsm_get_free_size(struct supertype *st, int raiddisks, (super->orom && used && used != raiddisks) || maxsize < minsize || maxsize == 0) { - fprintf(stderr, Name ": not enough devices with space to create array.\n"); + pr_err("not enough devices with space to create array.\n"); return 0; /* No enough free spaces large enough */ } @@ -6195,7 +6164,7 @@ static int imsm_get_free_size(struct supertype *st, int raiddisks, } if (!check_env("IMSM_NO_PLATFORM") && mpb->num_raid_devs > 0 && size && size != maxsize) { - fprintf(stderr, Name ": attempting to create a second " + pr_err("attempting to create a second " "volume with size less then remaining space. " "Aborting...\n"); return 0; @@ -6300,15 +6269,14 @@ static int validate_geometry_imsm(struct supertype *st, int level, int layout, fd = open(dev, O_RDONLY|O_EXCL, 0); if (fd >= 0) { if (verbose) - fprintf(stderr, - Name ": Cannot create this array on device %s\n", - dev); + pr_err("Cannot create this array on device %s\n", + dev); close(fd); return 0; } if (errno != EBUSY || (fd = open(dev, O_RDONLY, 0)) < 0) { if (verbose) - fprintf(stderr, Name ": Cannot open %s: %s\n", + pr_err("Cannot open %s: %s\n", dev, strerror(errno)); return 0; } @@ -6317,7 +6285,7 @@ static int validate_geometry_imsm(struct supertype *st, int level, int layout, close(fd); if (cfd < 0) { if (verbose) - fprintf(stderr, Name ": Cannot use %s: It is busy\n", + pr_err("Cannot use %s: It is busy\n", dev); return 0; } @@ -6345,7 +6313,7 @@ static int validate_geometry_imsm(struct supertype *st, int level, int layout, } if (verbose) - fprintf(stderr, Name ": failed container membership check\n"); + pr_err("failed container membership check\n"); close(cfd); return 0; @@ -6393,9 +6361,8 @@ static int kill_subarray_imsm(struct supertype *st) continue; sprintf(subarray, "%u", i); if (is_subarray_active(subarray, st->devname)) { - fprintf(stderr, - Name ": deleting subarray-%d would change the UUID of active subarray-%d, aborting\n", - current_vol, i); + pr_err("deleting subarray-%d would change the UUID of active subarray-%d, aborting\n", + current_vol, i); return 2; } @@ -6452,8 +6419,7 @@ static int update_subarray_imsm(struct supertype *st, char *subarray, int vol; if (is_subarray_active(subarray, st->devname)) { - fprintf(stderr, - Name ": Unable to update name of active subarray\n"); + pr_err("Unable to update name of active subarray\n"); return 2; } @@ -6602,14 +6568,14 @@ static struct mdinfo *container_content_imsm(struct supertype *st, char *subarra /* do not assemble arrays when not all attributes are supported */ if (imsm_check_attributes(mpb->attributes) == 0) { sb_errors = 1; - fprintf(stderr, Name ": Unsupported attributes in IMSM metadata." + pr_err("Unsupported attributes in IMSM metadata." "Arrays activation is blocked.\n"); } /* check for bad blocks */ if (imsm_bbm_log_size(super->anchor)) { - fprintf(stderr, Name ": BBM log found in IMSM metadata." - "Arrays activation is blocked.\n"); + pr_err("BBM log found in IMSM metadata." + "Arrays activation is blocked.\n"); sb_errors = 1; } @@ -6644,7 +6610,7 @@ static struct mdinfo *container_content_imsm(struct supertype *st, char *subarra */ if (dev->vol.migr_state && (migr_type(dev) == MIGR_STATE_CHANGE)) { - fprintf(stderr, Name ": cannot assemble volume '%.16s':" + pr_err("cannot assemble volume '%.16s':" " unsupported migration in progress\n", dev->volume); continue; @@ -6655,7 +6621,7 @@ static struct mdinfo *container_content_imsm(struct supertype *st, char *subarra this = malloc(sizeof(*this)); if (!this) { - fprintf(stderr, Name ": failed to allocate %zu bytes\n", + pr_err("failed to allocate %zu bytes\n", sizeof(*this)); break; } @@ -6672,7 +6638,7 @@ static struct mdinfo *container_content_imsm(struct supertype *st, char *subarra map->num_members, /* raid disks */ &chunk, join_u32(dev->size_low, dev->size_high), 1 /* verbose */)) { - fprintf(stderr, Name ": IMSM RAID geometry validation" + pr_err("IMSM RAID geometry validation" " failed. Array %s activation is blocked.\n", dev->volume); this->array.state |= @@ -6724,8 +6690,8 @@ static struct mdinfo *container_content_imsm(struct supertype *st, char *subarra info_d = calloc(1, sizeof(*info_d)); if (!info_d) { - fprintf(stderr, Name ": failed to allocate disk" - " for volume %.16s\n", dev->volume); + pr_err("failed to allocate disk" + " for volume %.16s\n", dev->volume); info_d = this->devs; while (info_d) { struct mdinfo *d = info_d->next; @@ -9276,7 +9242,7 @@ int save_backup_imsm(struct supertype *st, start, length, buf) != 0) { - fprintf(stderr, Name ": Error restoring stripes\n"); + pr_err("Error restoring stripes\n"); goto abort; } @@ -9412,8 +9378,7 @@ int recover_backup_imsm(struct supertype *st, struct mdinfo *info) goto abort; if (open_backup_targets(info, new_disks, targets, super, id->dev)) { - fprintf(stderr, - Name ": Cannot open some devices belonging to array.\n"); + pr_err("Cannot open some devices belonging to array.\n"); goto abort; } @@ -9423,30 +9388,26 @@ int recover_backup_imsm(struct supertype *st, struct mdinfo *info) continue; } if (lseek64(targets[i], read_offset, SEEK_SET) < 0) { - fprintf(stderr, - Name ": Cannot seek to block: %s\n", - strerror(errno)); + pr_err("Cannot seek to block: %s\n", + strerror(errno)); skipped_disks++; continue; } if ((unsigned)read(targets[i], buf, unit_len) != unit_len) { - fprintf(stderr, - Name ": Cannot read copy area block: %s\n", - strerror(errno)); + pr_err("Cannot read copy area block: %s\n", + strerror(errno)); skipped_disks++; continue; } if (lseek64(targets[i], write_offset, SEEK_SET) < 0) { - fprintf(stderr, - Name ": Cannot seek to block: %s\n", - strerror(errno)); + pr_err("Cannot seek to block: %s\n", + strerror(errno)); skipped_disks++; continue; } if ((unsigned)write(targets[i], buf, unit_len) != unit_len) { - fprintf(stderr, - Name ": Cannot restore block: %s\n", - strerror(errno)); + pr_err("Cannot restore block: %s\n", + strerror(errno)); skipped_disks++; continue; } @@ -9456,9 +9417,8 @@ int recover_backup_imsm(struct supertype *st, struct mdinfo *info) new_disks, super, id->dev)) { - fprintf(stderr, - Name ": Cannot restore data from backup." - " Too many failed disks\n"); + pr_err("Cannot restore data from backup." + " Too many failed disks\n"); goto abort; } @@ -9703,7 +9663,7 @@ static int imsm_create_metadata_update_for_reshape( if (spares == NULL || delta_disks > spares->array.spare_disks) { - fprintf(stderr, Name ": imsm: ERROR: Cannot get spare devices " + pr_err("imsm: ERROR: Cannot get spare devices " "for %s.\n", geo->dev_name); i = -1; goto abort; @@ -9915,10 +9875,9 @@ enum imsm_reshape_type imsm_analyze_change(struct supertype *st, if (geo->level == 5) { change = CH_MIGRATION; if (geo->layout != ALGORITHM_LEFT_ASYMMETRIC) { - fprintf(stderr, - Name " Error. Requested Layout " - "not supported (left-asymmetric layout " - "is supported only)!\n"); + pr_err("Error. Requested Layout " + "not supported (left-asymmetric layout " + "is supported only)!\n"); change = -1; goto analyse_change_exit; } @@ -9943,10 +9902,9 @@ enum imsm_reshape_type imsm_analyze_change(struct supertype *st, break; } if (change == -1) { - fprintf(stderr, - Name " Error. Level Migration from %d to %d " - "not supported!\n", - info.array.level, geo->level); + pr_err("Error. Level Migration from %d to %d " + "not supported!\n", + info.array.level, geo->level); goto analyse_change_exit; } } else @@ -9966,10 +9924,9 @@ enum imsm_reshape_type imsm_analyze_change(struct supertype *st, geo->layout = 0; geo->level = 5; } else { - fprintf(stderr, - Name " Error. Layout Migration from %d to %d " - "not supported!\n", - info.array.layout, geo->layout); + pr_err("Error. Layout Migration from %d to %d " + "not supported!\n", + info.array.layout, geo->layout); change = -1; goto analyse_change_exit; } @@ -10005,17 +9962,15 @@ enum imsm_reshape_type imsm_analyze_change(struct supertype *st, if ((current_size != geo->size) && (geo->size >= 0)) { if (change != -1) { - fprintf(stderr, - Name " Error. Size change should be the only " + pr_err("Error. Size change should be the only " "one at a time.\n"); change = -1; goto analyse_change_exit; } if ((super->current_vol + 1) != super->anchor->num_raid_devs) { - fprintf(stderr, - Name " Error. The last volume in container " - "can be expanded only (%i/%i).\n", - super->current_vol, st->devnum); + pr_err("Error. The last volume in container " + "can be expanded only (%i/%i).\n", + super->current_vol, st->devnum); goto analyse_change_exit; } /* check the maximum available size @@ -10039,7 +9994,7 @@ enum imsm_reshape_type imsm_analyze_change(struct supertype *st, /* requested size change to the maximum available size */ if (max_size == 0) { - fprintf(stderr, Name " Error. Cannot find " + pr_err("Error. Cannot find " "maximum available space.\n"); change = -1; goto analyse_change_exit; @@ -10058,20 +10013,18 @@ enum imsm_reshape_type imsm_analyze_change(struct supertype *st, dprintf("Prepare update for size change to %llu\n", geo->size ); if (current_size >= geo->size) { - fprintf(stderr, - Name " Error. Size expansion is " - "supported only (current size is %llu, " - "requested size /rounded/ is %llu).\n", - current_size, geo->size); + pr_err("Error. Size expansion is " + "supported only (current size is %llu, " + "requested size /rounded/ is %llu).\n", + current_size, geo->size); goto analyse_change_exit; } if (max_size && geo->size > max_size) { - fprintf(stderr, - Name " Error. Requested size is larger " - "than maximum available size (maximum " - "available size is %llu, " - "requested size /rounded/ is %llu).\n", - max_size, geo->size); + pr_err("Error. Requested size is larger " + "than maximum available size (maximum " + "available size is %llu, " + "requested size /rounded/ is %llu).\n", + max_size, geo->size); goto analyse_change_exit; } } @@ -10093,11 +10046,10 @@ enum imsm_reshape_type imsm_analyze_change(struct supertype *st, struct imsm_super *mpb = super->anchor; if (mpb->num_raid_devs > 1) { - fprintf(stderr, - Name " Error. Cannot perform operation on %s" - "- for this operation it MUST be single " - "array in container\n", - geo->dev_name); + pr_err("Error. Cannot perform operation on %s" + "- for this operation it MUST be single " + "array in container\n", + geo->dev_name); change = -1; } } @@ -10201,7 +10153,7 @@ static int imsm_reshape_super(struct supertype *st, long long size, int level, free(u); } else { - fprintf(stderr, Name ": (imsm) Operation " + pr_err("(imsm) Operation " "is not allowed on this container\n"); } } else { @@ -10223,7 +10175,7 @@ static int imsm_reshape_super(struct supertype *st, long long size, int level, dev = dev->next; } if (dev == NULL) { - fprintf(stderr, Name " Cannot find %s (%i) subarray\n", + pr_err("Cannot find %s (%i) subarray\n", geo.dev_name, geo.dev_id); goto exit_imsm_reshape_super; } @@ -10463,7 +10415,7 @@ static int imsm_manage_reshape( } /* Only one volume can migrate at the same time */ if (migr_vol_qan != 1) { - fprintf(stderr, Name " : %s", migr_vol_qan ? + pr_err(": %s", migr_vol_qan ? "Number of migrating volumes greater than 1\n" : "There is no volume during migrationg\n"); goto abort; diff --git a/super-mbr.c b/super-mbr.c index 64999637..3b0cc8d8 100644 --- a/super-mbr.c +++ b/super-mbr.c @@ -81,7 +81,7 @@ static int load_super_mbr(struct supertype *st, int fd, char *devname) free_mbr(st); if (posix_memalign((void**)&super, 512, 512) != 0) { - fprintf(stderr, Name ": %s could not allocate superblock\n", + pr_err("%s could not allocate superblock\n", __func__); return 1; } @@ -91,7 +91,7 @@ static int load_super_mbr(struct supertype *st, int fd, char *devname) lseek(fd, 0, 0); if (read(fd, super, sizeof(*super)) != sizeof(*super)) { if (devname) - fprintf(stderr, Name ": Cannot read partition table on %s\n", + pr_err("Cannot read partition table on %s\n", devname); free(super); return 1; @@ -99,7 +99,7 @@ static int load_super_mbr(struct supertype *st, int fd, char *devname) if (super->magic != MBR_SIGNATURE_MAGIC) { if (devname) - fprintf(stderr, Name ": No partition table found on %s\n", + pr_err("No partition table found on %s\n", devname); free(super); return 1; @@ -121,7 +121,7 @@ static int store_mbr(struct supertype *st, int fd) struct MBR *old, *super; if (posix_memalign((void**)&old, 512, 512) != 0) { - fprintf(stderr, Name ": %s could not allocate superblock\n", + pr_err("%s could not allocate superblock\n", __func__); return 1; } @@ -192,7 +192,7 @@ static int validate_geometry(struct supertype *st, int level, char *subdev, unsigned long long *freesize, int verbose) { - fprintf(stderr, Name ": mbr metadata cannot be used this way\n"); + pr_err("mbr metadata cannot be used this way\n"); return 0; } #endif diff --git a/super0.c b/super0.c index 13757998..c8cbb9d9 100644 --- a/super0.c +++ b/super0.c @@ -445,12 +445,12 @@ static int update_super0(struct supertype *st, struct mdinfo *info, sb32+MD_SB_GENERIC_CONSTANT_WORDS+7+1, (MD_SB_WORDS - (MD_SB_GENERIC_CONSTANT_WORDS+7+1))*4); if (verbose >= 0) - fprintf (stderr, Name ": adjusting superblock of %s for 2.2/sparc compatability.\n", - devname); + pr_err("adjusting superblock of %s for 2.2/sparc compatability.\n", + devname); } else if (strcmp(update, "super-minor") ==0) { sb->md_minor = info->array.md_minor; if (verbose > 0) - fprintf(stderr, Name ": updating superblock of %s with minor number %d\n", + pr_err("updating superblock of %s with minor number %d\n", devname, info->array.md_minor); } else if (strcmp(update, "summaries") == 0) { unsigned int i; @@ -608,7 +608,7 @@ static int init_super0(struct supertype *st, mdu_array_info_t *info, if (posix_memalign((void**)&sb, 4096, MD_SB_BYTES + ROUND_UP(sizeof(bitmap_super_t), 4096)) != 0) { - fprintf(stderr, Name ": %s could not allocate superblock\n", __func__); + pr_err("%s could not allocate superblock\n", __func__); return 0; } memset(sb, 0, MD_SB_BYTES + sizeof(bitmap_super_t)); @@ -621,7 +621,7 @@ static int init_super0(struct supertype *st, mdu_array_info_t *info, spares = info->working_disks - info->active_disks; if (info->raid_disks + spares > MD_SB_DISKS) { - fprintf(stderr, Name ": too many devices requested: %d+%d > %d\n", + pr_err("too many devices requested: %d+%d > %d\n", info->raid_disks , spares, MD_SB_DISKS); return 0; } @@ -781,9 +781,8 @@ static int write_init_super0(struct supertype *st) rv = st->ss->write_bitmap(st, di->fd); if (rv) - fprintf(stderr, - Name ": failed to write superblock to %s\n", - di->devname); + pr_err("failed to write superblock to %s\n", + di->devname); } return rv; } @@ -808,8 +807,7 @@ static int compare_super0(struct supertype *st, struct supertype *tst) if (posix_memalign((void**)&first, 4096, MD_SB_BYTES + ROUND_UP(sizeof(struct bitmap_super_s), 4096)) != 0) { - fprintf(stderr, Name - ": %s could not allocate superblock\n", __func__); + pr_err("%s could not allocate superblock\n", __func__); return 1; } memcpy(first, second, MD_SB_BYTES + sizeof(struct bitmap_super_s)); @@ -858,9 +856,8 @@ static int load_super0(struct supertype *st, int fd, char *devname) if (dsize < MD_RESERVED_SECTORS*512) { if (devname) - fprintf(stderr, Name - ": %s is too small for md: size is %llu sectors.\n", - devname, dsize); + pr_err("%s is too small for md: size is %llu sectors.\n", + devname, dsize); return 1; } @@ -872,7 +869,7 @@ static int load_super0(struct supertype *st, int fd, char *devname) if (lseek64(fd, offset, 0)< 0LL) { if (devname) - fprintf(stderr, Name ": Cannot seek to superblock on %s: %s\n", + pr_err("Cannot seek to superblock on %s: %s\n", devname, strerror(errno)); return 1; } @@ -880,14 +877,13 @@ static int load_super0(struct supertype *st, int fd, char *devname) if (posix_memalign((void**)&super, 4096, MD_SB_BYTES + ROUND_UP(sizeof(bitmap_super_t), 4096)) != 0) { - fprintf(stderr, Name - ": %s could not allocate superblock\n", __func__); + pr_err("%s could not allocate superblock\n", __func__); return 1; } if (read(fd, super, sizeof(*super)) != MD_SB_BYTES) { if (devname) - fprintf(stderr, Name ": Cannot read superblock on %s\n", + pr_err("Cannot read superblock on %s\n", devname); free(super); return 1; @@ -898,7 +894,7 @@ static int load_super0(struct supertype *st, int fd, char *devname) if (super->md_magic != MD_SB_MAGIC) { if (devname) - fprintf(stderr, Name ": No super block found on %s (Expected magic %08x, got %08x)\n", + pr_err("No super block found on %s (Expected magic %08x, got %08x)\n", devname, MD_SB_MAGIC, super->md_magic); free(super); return 2; @@ -906,7 +902,7 @@ static int load_super0(struct supertype *st, int fd, char *devname) if (super->major_version != 0) { if (devname) - fprintf(stderr, Name ": Cannot interpret superblock on %s - version is %d\n", + pr_err("Cannot interpret superblock on %s - version is %d\n", devname, super->major_version); free(super); return 2; @@ -1142,19 +1138,19 @@ static int validate_geometry0(struct supertype *st, int level, if (level == LEVEL_CONTAINER) { if (verbose) - fprintf(stderr, Name ": 0.90 metadata does not support containers\n"); + pr_err("0.90 metadata does not support containers\n"); return 0; } if (raiddisks > MD_SB_DISKS) { if (verbose) - fprintf(stderr, Name ": 0.90 metadata supports at most %d devices per array\n", + pr_err("0.90 metadata supports at most %d devices per array\n", MD_SB_DISKS); return 0; } if (size >= tbmax * 2ULL*1024*1024*1024) { if (verbose) - fprintf(stderr, Name ": 0.90 metadata supports at most " - "%d terabytes per device\n", tbmax); + pr_err("0.90 metadata supports at most " + "%d terabytes per device\n", tbmax); return 0; } if (chunk && *chunk == UnSet) @@ -1166,7 +1162,7 @@ static int validate_geometry0(struct supertype *st, int level, fd = open(subdev, O_RDONLY|O_EXCL, 0); if (fd < 0) { if (verbose) - fprintf(stderr, Name ": super0.90 cannot open %s: %s\n", + pr_err("super0.90 cannot open %s: %s\n", subdev, strerror(errno)); return 0; } diff --git a/super1.c b/super1.c index fbc2e8fa..5c6530ed 100644 --- a/super1.c +++ b/super1.c @@ -871,8 +871,7 @@ static int init_super1(struct supertype *st, mdu_array_info_t *info, int sbsize; if (posix_memalign((void**)&sb, 4096, SUPER1_SIZE) != 0) { - fprintf(stderr, Name - ": %s could not allocate superblock\n", __func__); + pr_err("%s could not allocate superblock\n", __func__); return 0; } memset(sb, 0, SUPER1_SIZE); @@ -885,7 +884,7 @@ static int init_super1(struct supertype *st, mdu_array_info_t *info, spares = info->working_disks - info->active_disks; if (info->raid_disks + spares > MAX_DEVS) { - fprintf(stderr, Name ": too many devices requested: %d+%d > %d\n", + pr_err("too many devices requested: %d+%d > %d\n", info->raid_disks , spares, MAX_DEVS); return 0; } @@ -1039,7 +1038,7 @@ static int store_super1(struct supertype *st, int fd) if (sb_offset != __le64_to_cpu(sb->super_offset) && 0 != __le64_to_cpu(sb->super_offset) ) { - fprintf(stderr, Name ": internal error - sb_offset is wrong\n"); + pr_err("internal error - sb_offset is wrong\n"); abort(); } @@ -1229,9 +1228,9 @@ static int write_init_super1(struct supertype *st) sb->data_size = __cpu_to_le64(dsize - reserved); break; default: - fprintf(stderr, Name ": Failed to write invalid " - "metadata format 1.%i to %s\n", - st->minor_version, di->devname); + pr_err("Failed to write invalid " + "metadata format 1.%i to %s\n", + st->minor_version, di->devname); rv = -EINVAL; goto out; } @@ -1247,8 +1246,8 @@ static int write_init_super1(struct supertype *st) } error_out: if (rv) - fprintf(stderr, Name ": Failed to write metadata to %s\n", - di->devname); + pr_err("Failed to write metadata to %s\n", + di->devname); out: return rv; } @@ -1273,8 +1272,7 @@ static int compare_super1(struct supertype *st, struct supertype *tst) if (!first) { if (posix_memalign((void**)&first, 4096, SUPER1_SIZE) != 0) { - fprintf(stderr, Name - ": %s could not allocate superblock\n", __func__); + pr_err("%s could not allocate superblock\n", __func__); return 1; } memcpy(first, second, SUPER1_SIZE); @@ -1348,7 +1346,7 @@ static int load_super1(struct supertype *st, int fd, char *devname) if (dsize < 24) { if (devname) - fprintf(stderr, Name ": %s is too small for md: size is %llu sectors.\n", + pr_err("%s is too small for md: size is %llu sectors.\n", devname, dsize); return 1; } @@ -1382,20 +1380,20 @@ static int load_super1(struct supertype *st, int fd, char *devname) if (lseek64(fd, sb_offset << 9, 0)< 0LL) { if (devname) - fprintf(stderr, Name ": Cannot seek to superblock on %s: %s\n", + pr_err("Cannot seek to superblock on %s: %s\n", devname, strerror(errno)); return 1; } if (posix_memalign((void**)&super, 4096, SUPER1_SIZE) != 0) { - fprintf(stderr, Name ": %s could not allocate superblock\n", + pr_err("%s could not allocate superblock\n", __func__); return 1; } if (aread(&afd, super, MAX_SB_SIZE) != MAX_SB_SIZE) { if (devname) - fprintf(stderr, Name ": Cannot read superblock on %s\n", + pr_err("Cannot read superblock on %s\n", devname); free(super); return 1; @@ -1403,7 +1401,7 @@ static int load_super1(struct supertype *st, int fd, char *devname) if (__le32_to_cpu(super->magic) != MD_SB_MAGIC) { if (devname) - fprintf(stderr, Name ": No super block found on %s (Expected magic %08x, got %08x)\n", + pr_err("No super block found on %s (Expected magic %08x, got %08x)\n", devname, MD_SB_MAGIC, __le32_to_cpu(super->magic)); free(super); return 2; @@ -1411,14 +1409,14 @@ static int load_super1(struct supertype *st, int fd, char *devname) if (__le32_to_cpu(super->major_version) != 1) { if (devname) - fprintf(stderr, Name ": Cannot interpret superblock on %s - version is %d\n", + pr_err("Cannot interpret superblock on %s - version is %d\n", devname, __le32_to_cpu(super->major_version)); free(super); return 2; } if (__le64_to_cpu(super->super_offset) != sb_offset) { if (devname) - fprintf(stderr, Name ": No superblock found on %s (super_offset is wrong)\n", + pr_err("No superblock found on %s (super_offset is wrong)\n", devname); free(super); return 2; @@ -1760,7 +1758,7 @@ static int validate_geometry1(struct supertype *st, int level, if (level == LEVEL_CONTAINER) { if (verbose) - fprintf(stderr, Name ": 1.x metadata does not support containers\n"); + pr_err("1.x metadata does not support containers\n"); return 0; } if (chunk && *chunk == UnSet) @@ -1772,7 +1770,7 @@ static int validate_geometry1(struct supertype *st, int level, fd = open(subdev, O_RDONLY|O_EXCL, 0); if (fd < 0) { if (verbose) - fprintf(stderr, Name ": super1.x cannot open %s: %s\n", + pr_err("super1.x cannot open %s: %s\n", subdev, strerror(errno)); return 0; } diff --git a/sysfs.c b/sysfs.c index 8e9d0c5a..036a4ffc 100644 --- a/sysfs.c +++ b/sysfs.c @@ -580,7 +580,7 @@ int sysfs_set_array(struct mdinfo *info, int vers) if ((vers % 100) < 2 || sysfs_set_str(info, NULL, "metadata_version", ver) < 0) { - fprintf(stderr, Name ": This kernel does not " + pr_err("This kernel does not " "support external metadata.\n"); return 1; } @@ -601,7 +601,7 @@ int sysfs_set_array(struct mdinfo *info, int vers) rc = sysfs_set_num(info, NULL, "array_size", info->custom_array_size/2); if (rc && errno == ENOENT) { - fprintf(stderr, Name ": This kernel does not " + pr_err("This kernel does not " "have the md/array_size attribute, " "the array may be larger than expected\n"); rc = 0; diff --git a/util.c b/util.c index ac0f78c5..d939e06c 100644 --- a/util.c +++ b/util.c @@ -505,7 +505,7 @@ int check_ext2(int fd, char *name) mtime = sb[44]|(sb[45]|(sb[46]|sb[47]<<8)<<8)<<8; bsize = sb[24]|(sb[25]|(sb[26]|sb[27]<<8)<<8)<<8; size = sb[4]|(sb[5]|(sb[6]|sb[7]<<8)<<8)<<8; - fprintf(stderr, Name ": %s appears to contain an ext2fs file system\n", + pr_err("%s appears to contain an ext2fs file system\n", name); fprintf(stderr," size=%dK mtime=%s", size*(1<ignore_hw_compat = 1; st->ss->load_super(st, fd, name); /* Looks like a raid array .. */ - fprintf(stderr, Name ": %s appears to be part of a raid array:\n", + pr_err("%s appears to be part of a raid array:\n", name); st->ss->getinfo_super(st, &info, NULL); st->ss->free_super(st); @@ -575,7 +575,7 @@ int ask(char *mesg) return 0; add = "(y/n) "; } - fprintf(stderr, Name ": assuming 'no'\n"); + pr_err("assuming 'no'\n"); return 0; } #endif /* MDASSEMBLE */ @@ -1106,7 +1106,7 @@ int get_dev_size(int fd, char *dname, unsigned long long *sizep) ldsize <<= 9; } else { if (dname) - fprintf(stderr, Name ": Cannot get size of %s: %s\b", + pr_err("Cannot get size of %s: %s\b", dname, strerror(errno)); return 0; } @@ -1248,22 +1248,19 @@ int check_partitions(int fd, char *dname, unsigned long long freesize, /* There appears to be a partition table here */ if (freesize == 0) { /* partitions will not be visible in new device */ - fprintf(stderr, - Name ": partition table exists on %s but will be lost or\n" - " meaningless after creating array\n", - dname); + pr_err("partition table exists on %s but will be lost or\n" + " meaningless after creating array\n", + dname); return 1; } else if (endofpart > freesize) { /* last partition overlaps metadata */ - fprintf(stderr, - Name ": metadata will over-write last partition on %s.\n", - dname); + pr_err("metadata will over-write last partition on %s.\n", + dname); return 1; } else if (size && endofpart > size) { /* partitions will be truncated in new device */ - fprintf(stderr, - Name ": array size is too small to cover all partitions on %s.\n", - dname); + pr_err("array size is too small to cover all partitions on %s.\n", + dname); return 1; } } @@ -1389,7 +1386,7 @@ int open_subarray(char *dev, char *subarray, struct supertype *st, int quiet) fd = open(dev, O_RDWR|O_EXCL); if (fd < 0) { if (!quiet) - fprintf(stderr, Name ": Couldn't open %s, aborting\n", + pr_err("Couldn't open %s, aborting\n", dev); return -1; } @@ -1397,51 +1394,49 @@ int open_subarray(char *dev, char *subarray, struct supertype *st, int quiet) st->devnum = fd2devnum(fd); if (st->devnum == NoMdDev) { if (!quiet) - fprintf(stderr, - Name ": Failed to determine device number for %s\n", - dev); + pr_err("Failed to determine device number for %s\n", + dev); goto close_fd; } mdi = sysfs_read(fd, st->devnum, GET_VERSION|GET_LEVEL); if (!mdi) { if (!quiet) - fprintf(stderr, Name ": Failed to read sysfs for %s\n", + pr_err("Failed to read sysfs for %s\n", dev); goto close_fd; } if (mdi->array.level != UnSet) { if (!quiet) - fprintf(stderr, Name ": %s is not a container\n", dev); + pr_err("%s is not a container\n", dev); goto free_sysfs; } st->ss = version_to_superswitch(mdi->text_version); if (!st->ss) { if (!quiet) - fprintf(stderr, - Name ": Operation not supported for %s metadata\n", - mdi->text_version); + pr_err("Operation not supported for %s metadata\n", + mdi->text_version); goto free_sysfs; } st->devname = devnum2devname(st->devnum); if (!st->devname) { if (!quiet) - fprintf(stderr, Name ": Failed to allocate device name\n"); + pr_err("Failed to allocate device name\n"); goto free_sysfs; } if (!st->ss->load_container) { if (!quiet) - fprintf(stderr, Name ": %s is not a container\n", dev); + pr_err("%s is not a container\n", dev); goto free_name; } if (st->ss->load_container(st, fd, NULL)) { if (!quiet) - fprintf(stderr, Name ": Failed to load metadata for %s\n", + pr_err("Failed to load metadata for %s\n", dev); goto free_name; } @@ -1449,7 +1444,7 @@ int open_subarray(char *dev, char *subarray, struct supertype *st, int quiet) info = st->ss->container_content(st, subarray); if (!info) { if (!quiet) - fprintf(stderr, Name ": Failed to find subarray-%s in %s\n", + pr_err("Failed to find subarray-%s in %s\n", subarray, dev); goto free_super; } @@ -1645,7 +1640,7 @@ int start_mdmon(int devnum) } } exit(1); - case -1: fprintf(stderr, Name ": cannot run mdmon. " + case -1: pr_err("cannot run mdmon. " "Array remains readonly\n"); return -1; default: /* parent - good */ @@ -1731,7 +1726,7 @@ int experimental(void) if (check_env("MDADM_EXPERIMENTAL")) return 1; else { - fprintf(stderr, Name ": To use this feature MDADM_EXPERIMENTAL" + pr_err("To use this feature MDADM_EXPERIMENTAL" " environment variable has to be defined.\n"); return 0; }