}
/* Make sure device is large enough */
- if (tst->ss->avail_size(tst, ldsize/512) <
+ if (tst->ss->avail_size(tst, ldsize/512, INVALID_SECTORS) <
array_size) {
if (dv->disposition == 'M')
return 0;
return -1;
}
+ Kill(dv->devname, NULL, 0, -1, 0);
dfd = dev_open(dv->devname, O_RDWR | O_EXCL|O_DIRECT);
if (mdmon_running(tst->container_dev))
tst->update_tail = &tst->updates;
* hot spare while we are checking, we
* get an O_EXCL open on the container
*/
+ int ret;
int dnum = fd2devnum(fd);
lfd = open_dev_excl(dnum);
if (lfd < 0) {
" to container - odd\n");
return -1;
}
- /* In the detached case it is not possible to
- * check if we are the unique holder, so just
- * rely on the 'detached' checks
+ /* We may not be able to check on holders in
+ * sysfs, either because we don't have the dev num
+ * (rdev == 0) or because the device has been detached
+ * and the 'holders' directory no longer exists
+ * (ret == -1). In that case, assume it is OK to
+ * remove.
*/
- if (strcmp(dv->devname, "detached") == 0 ||
- sysfd >= 0 ||
- sysfs_unique_holder(dnum, rdev))
- /* pass */;
- else {
- pr_err("%s is %s, cannot remove.\n",
- dv->devname,
- errno == EEXIST ? "still in use":
- "not a member");
+ if (rdev == 0)
+ ret = -1;
+ else
+ ret = sysfs_unique_holder(dnum, rdev);
+ if (ret == 0) {
+ pr_err("%s is not a member, cannot remove.\n",
+ dv->devname);
+ close(lfd);
+ return -1;
+ }
+ if (ret >= 2) {
+ pr_err("%s is still in use, cannot remove.\n",
+ dv->devname);
close(lfd);
return -1;
}
struct mddev_dev **dp;
if (dv->disposition != 'A') {
pr_err("'missing' only meaningful "
- "with --re-add\n");
+ "with --re-add\n");
goto abort;
}
add_devlist = conf_get_devs();
}
if (strchr(dv->devname, '/') == NULL &&
- strchr(dv->devname, ':') == NULL &&
- strlen(dv->devname) < 50) {
+ strchr(dv->devname, ':') == NULL &&
+ strlen(dv->devname) < 50) {
/* Assume this is a kernel-internal name like 'sda1' */
int found = 0;
char dname[55];