LVM2 ./WHATS_NEW_DM libdm/ioctl/libdm-iface.c
CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: prajnoha at sourceware.org 2011-09-13 15:13:41
Modified files:
. : WHATS_NEW_DM
libdm/ioctl : libdm-iface.c
Log message:
Retry DM_DEVICE_REMOVE ioctl if device is busy.
This is a workaround for long-lasting problem with using the WATCH udev rule. When trying to remove a DM device, this one can still be opened while processing the event in parallel (generated based on the WATCH udev rule).
Let's use this until we have a proper solution.
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW_DM.diff?cvsroot=lvm2&r1=1.498&r2=1.499
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/libdm/ioctl/libdm-iface.c.diff?cvsroot=lvm2&r1=1.119&r2=1.120
WHATS_NEW_DM +1 -0
@@ -1,5 +1,6 @@ Version 1.02.68 - ================================== + Retry DM_DEVICE_REMOVE ioctl if device is busy. Remove unused passed parameters for _mirror_emit_segment_line(). Add dm_config and string character escaping functions to libdevmapper. Mark unreleased memory pools as internal error.
libdm/ioctl/libdm-iface.c +15 -0
@@ -1539,11 +1539,14 @@return sanitised_message; } +#define DM_REMOVE_IOCTL_RETRIES 25 +static struct dm_ioctl *_do_dm_ioctl (struct dm_task *dmt,unsigned command,unsigned repeat_count) {struct dm_ioctl *dmi;int ioctl_with_uevent; +int retries =DM_REMOVE_IOCTL_RETRIES ; dmi =_flatten (dmt, repeat_count);if (!dmi) {
@@ -1627,11 +1630,23 @@ dmt->sector,_sanitise_message (dmt->message), dmi->data_size);#ifdef DM_IOCTLS +repeat_dm_ioctl:if (ioctl (_control_fd, command, dmi) <0 ) {if (errno ==ENXIO && ((dmt->type ==DM_DEVICE_INFO ) || (dmt->type ==DM_DEVICE_MKNODES ) || (dmt->type ==DM_DEVICE_STATUS ))) dmi->flags &= ~DM_EXISTS_FLAG ;/* FIXME */ +/* +* FIXME: This is a workaround for asynchronous events generated +* as a result of using the WATCH udev rule with which we +* have no way of synchronizing. Processing such events in +* parallel causes devices to be open. +*/ +else if (errno ==EBUSY && (dmt->type ==DM_DEVICE_REMOVE ) && retries--) { +log_debug ("device-mapper: device is busy, retrying removal" ); +usleep (200000 ); + goto repeat_dm_ioctl; + }else {if (_log_suppress) log_verbose("device-mapper: %s ioctl "
Quoted 1 line · prajnoha at sourceware.org
Let's use this until we have a proper solution.
That patch is unsuitable for general release and needs to be reverted in my opinion.
There is a fallacy in assuming that the udev problem is the only reason for the detected failure and then installing the defensive action on unaffected code paths. There are cases in which repeating the remove ioctl will make no difference and the code will continue to see EBUSY and an enforced 5 second delay risks causing some people new problems. But with just a little more effort, you can obtain the best of both worlds.
Please update the patch to address the following points:
1. Currently the ioctl buffer contents are 'undefined' when the ioctl returns an error. I'm not happy to assume the buffer will always be unchanged if there's an error - it should be repopulated before reuse. (This basically means I want the repeat loop in a higher layer of the code, or a new flag defining...
- Hmmm. Mikulas - Have we just broken the BUFFER_FULL logic with
dm-ioctl-forbid-multiple-device-specifiers.patch? Might have to revert that kernel patch or update it only to complain if the multiple specifiers don't all point to the same device...)
2. The repeat must be made conditional, so it only occurs in potential problem cases i.e. filter out as many 'OK' cases as you possibly can.
- if udev is not involved (which we already know from other variables) skip this code (easy)
- consider any other easy tests that can narrow the filtering
3. 'dmsetup remove' must not use the new behaviour by default, or you risk affecting some people's existing scripts adversely. Add a new cmdline switch to enable this. I do not think it should be enabled by default. Keep sight of the fact that the cases you're trying to improve involve specific *sequences* of commands run in quick succession and there are no grounds for removing functionality from dmsetup/libdevmapper by denying users the ability to run individual ioctls and allowing them to handle the failures as *they* see fit.
4. We can't rule out unanticipated side-effects on the lvm2 side either, so, while enabled by default when udev is in use, it must still be possible to turn off the feature at run time, using an lvm.conf setting.
5. I've seen no empirical evidence yet to justify the selection of the number of retries and the sleep time. E.g. Please provide some base data on the length of a typical delay/number of repeated attempts caused by a common problematic udev rule firing to back up the numbers chosen, and consider whether 'one size fits all' is suitable or if it needs to be tunable (is 5 seconds long enough on a slow and loaded system?), or could it itself be triggered by something else?
Alasdair
Quoted 16 lines · Alasdair G Kergon
Quoted 1 line · prajnoha at sourceware.org
Let's use this until we have a proper solution.
That patch is unsuitable for general release and needs to be reverted in my opinion.
There is a fallacy in assuming that the udev problem is the only reason for the detected failure and then installing the defensive action on unaffected code paths. There are cases in which repeating the remove ioctl will make no difference and the code will continue to see EBUSY and an enforced 5 second delay risks causing some people new problems. But with just a little more effort, you can obtain the best of both worlds.
Please update the patch to address the following points:
Quoted 9 lines
1. Currently the ioctl buffer contents are 'undefined' when the ioctl returns an error. I'm not happy to assume the buffer will always be unchanged if there's an error - it should be repopulated before reuse. (This basically means I want the repeat loop in a higher layer of the code, or a new flag defining...
- Hmmm. Mikulas - Have we just broken theBUFFER_FULLlogic with
dm-ioctl-forbid-multiple-device-specifiers.patch? Might have to revert that kernel patch or update it only to complain if the multiple specifiers don't all point to the same device...)
We haven't broken BUFFER_FULL ... see my other email. I tested it and reviewed the code and it is ok.
But it is true that this patch is wrong and breaks is. Repeat should be done at the higher level, just like BUFFER_FULL repeating.
Mikulas
Quoted 27 lines
2. The repeat must be made conditional, so it only occurs in potential problem cases i.e. filter out as many 'OK' cases as you possibly can.
- if udev is not involved (which we already know from other variables) skip this code (easy)
- consider any other easy tests that can narrow the filtering3. 'dmsetup remove' must not use the new behaviour by default, or you risk affecting some people's existing scripts adversely. Add a new cmdline switch to enable this. I do not think it should be enabled by default. Keep sight of the fact that the cases you're trying to improve involve specific *sequences* of commands run in quick succession and there are no grounds for removing functionality from dmsetup/libdevmapper by denying users the ability to run individual ioctls and allowing them to handle the failures as *they* see fit.
4. We can't rule out unanticipated side-effects on the lvm2 side either, so, while enabled by default when udev is in use, it must still be possible to turn off the feature at run time, using an lvm.conf setting.
5. I've seen no empirical evidence yet to justify the selection of the number of retries and the sleep time. E.g. Please provide some base data on the length of a typical delay/number of repeated attempts caused by a common problematic udev rule firing to back up the numbers chosen, and consider whether 'one size fits all' is suitable or if it needs to be tunable (is 5 seconds long enough on a slow and loaded system?), or could it itself be triggered by something else?
Alasdair