unsigned long new_size = info.size;
if (new_size != size) {
+ dout(5) << "resize detected" << dendl;
if (ioctl(fd, BLKFLSBUF, NULL) < 0)
- derr << "invalidate page cache failed: " << cpp_strerror(errno) << dendl;
+ derr << "invalidate page cache failed: " << cpp_strerror(errno)
+ << dendl;
if (ioctl(fd, NBD_SET_SIZE, new_size) < 0) {
derr << "resize failed: " << cpp_strerror(errno) << dendl;
} else {
size = new_size;
}
+ if (ioctl(fd, BLKRRPART, NULL) < 0) {
+ derr << "rescan of partition table failed: " << cpp_strerror(errno)
+ << dendl;
+ }
if (image.invalidate_cache() < 0)
derr << "invalidate rbd cache failed" << dendl;
}
if (cfg->devpath.empty()) {
char dev[64];
bool try_load_module = true;
+ const char *path = "/sys/module/nbd/parameters/nbds_max";
+ int nbds_max = -1;
+ if (access(path, F_OK) == 0) {
+ std::ifstream ifs;
+ ifs.open(path, std::ifstream::in);
+ if (ifs.is_open()) {
+ ifs >> nbds_max;
+ ifs.close();
+ }
+ }
+
while (true) {
snprintf(dev, sizeof(dev), "/dev/nbd%d", index);
nbd = open_device(dev, cfg, try_load_module);
try_load_module = false;
if (nbd < 0) {
+ if (nbd == -EPERM && nbds_max != -1 && index < (nbds_max-1)) {
+ ++index;
+ continue;
+ }
r = nbd;
cerr << "rbd-nbd: failed to find unused device" << std::endl;
goto close_fd;
std::vector<const char*> args;
ifs.open(path.c_str(), std::ifstream::in);
- assert (ifs.is_open());
+ if (!ifs.is_open())
+ return -1;
ifs >> cmdline;
for (unsigned i = 0; i < cmdline.size(); i++) {