X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=util.c;h=e32d97a011e7a791870f1015830a363e19167a0e;hb=fdcd157a8034fe5c896e49c4764d8ceef72e3741;hp=c12fb2115742f3a363af741da46cc14d3ebebc8c;hpb=2f1bcf43d93a991845b2ebee76850bd4dc5bc7fc;p=thirdparty%2Fmdadm.git diff --git a/util.c b/util.c index c12fb211..e32d97a0 100644 --- a/util.c +++ b/util.c @@ -1,7 +1,7 @@ /* * mdadm - manage Linux "md" devices aka RAID arrays. * - * Copyright (C) 2001-2012 Neil Brown + * Copyright (C) 2001-2013 Neil Brown * * * This program is free software; you can redistribute it and/or modify @@ -307,7 +307,7 @@ int test_partition(int fd) if (ioctl(fd, BLKPG, &a) == 0) /* Very unlikely, but not a partition */ return 0; - if (errno == ENXIO) + if (errno == ENXIO || errno == ENOTTY) /* not a partition */ return 0; @@ -387,7 +387,6 @@ int enough_fd(int fd) { struct mdu_array_info_s array; struct mdu_disk_info_s disk; - int avail_disks = 0; int i, rv; char *avail; @@ -407,7 +406,6 @@ int enough_fd(int fd) continue; if (disk.raid_disk < 0 || disk.raid_disk >= array.raid_disks) continue; - avail_disks++; avail[disk.raid_disk] = 1; } /* This is used on an active array, so assume it is clean */ @@ -1952,3 +1950,17 @@ int in_initrd(void) ((unsigned long)s.f_type == TMPFS_MAGIC || (unsigned long)s.f_type == RAMFS_MAGIC); } + +void reopen_mddev(int mdfd) +{ + /* Re-open without any O_EXCL, but keep + * the same fd + */ + char *devnm; + int fd; + devnm = fd2devnm(mdfd); + close(mdfd); + fd = open_dev(devnm); + if (fd >= 0 && fd != mdfd) + dup2(fd, mdfd); +}