Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mimic: krbd: fix rbd map hang due to udev return subsystem unordered #30176

Merged
merged 1 commit into from Oct 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 39 additions & 24 deletions src/krbd.cc
Expand Up @@ -184,6 +184,8 @@ static int wait_for_udev_add(struct udev_monitor *mon, const char *pool,
string *pname)
{
struct udev_device *bus_dev = nullptr;
std::vector<struct udev_device*> block_dev_vec;
int r;

/*
* Catch /sys/devices/rbd/<id>/ and wait for the corresponding
Expand All @@ -193,16 +195,16 @@ static int wait_for_udev_add(struct udev_monitor *mon, const char *pool,
for (;;) {
struct pollfd fds[1];
struct udev_device *dev;
int r;

fds[0].fd = udev_monitor_get_fd(mon);
fds[0].events = POLLIN;
r = poll(fds, 1, POLL_TIMEOUT);
if (r < 0)
return -errno;

if (r == 0)
return -ETIMEDOUT;
if (r > 0) {
r = 0;
} else {
r = (r == 0) ? -ETIMEDOUT : -errno;
break;
}

dev = udev_monitor_receive_device(mon);
if (!dev)
Expand All @@ -211,8 +213,8 @@ static int wait_for_udev_add(struct udev_monitor *mon, const char *pool,
if (strcmp(udev_device_get_action(dev), "add") != 0)
goto next;

if (!bus_dev) {
if (strcmp(udev_device_get_subsystem(dev), "rbd") == 0) {
if (strcmp(udev_device_get_subsystem(dev), "rbd") == 0) {
if (!bus_dev) {
const char *this_pool = udev_device_get_sysattr_value(dev, "pool");
const char *this_image = udev_device_get_sysattr_value(dev, "name");
const char *this_snap = udev_device_get_sysattr_value(dev,
Expand All @@ -222,37 +224,50 @@ static int wait_for_udev_add(struct udev_monitor *mon, const char *pool,
this_image && strcmp(this_image, image) == 0 &&
this_snap && strcmp(this_snap, snap) == 0) {
bus_dev = dev;
continue;
goto check;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This conditional block is where I had to resolve conflicts manually, and I'm not super confident the conflict resolution is correct.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine.

}
}
} else {
if (strcmp(udev_device_get_subsystem(dev), "block") == 0) {
const char *major = udev_device_get_sysattr_value(bus_dev, "major");
const char *minor = udev_device_get_sysattr_value(bus_dev, "minor");
const char *this_major = udev_device_get_property_value(dev, "MAJOR");
const char *this_minor = udev_device_get_property_value(dev, "MINOR");
} else if (strcmp(udev_device_get_subsystem(dev), "block") == 0) {
block_dev_vec.push_back(dev);
goto check;
}

next:
udev_device_unref(dev);
continue;

check:
if (bus_dev && !block_dev_vec.empty()) {
const char *major = udev_device_get_sysattr_value(bus_dev, "major");
const char *minor = udev_device_get_sysattr_value(bus_dev, "minor");
assert(!minor ^ have_minor_attr());

assert(!minor ^ have_minor_attr());
for (auto p : block_dev_vec) {
const char *this_major = udev_device_get_property_value(p, "MAJOR");
const char *this_minor = udev_device_get_property_value(p, "MINOR");

if (strcmp(this_major, major) == 0 &&
(!minor || strcmp(this_minor, minor) == 0)) {
string name = get_kernel_rbd_name(udev_device_get_sysname(bus_dev));

assert(strcmp(udev_device_get_devnode(dev), name.c_str()) == 0);
assert(strcmp(udev_device_get_devnode(p), name.c_str()) == 0);
*pname = name;

udev_device_unref(dev);
udev_device_unref(bus_dev);
break;
goto done;
}
}
}
}

next:
udev_device_unref(dev);
done:
if (bus_dev) {
udev_device_unref(bus_dev);
}

for (auto p : block_dev_vec) {
udev_device_unref(p);
}

return 0;
return r;
}

static int do_map(struct udev *udev, const char *pool, const char *image,
Expand Down