summaryrefslogtreecommitdiffstats
path: root/discover/udev.c
Commit message (Collapse)AuthorAgeFilesLines
* discover: Pass UUID to discover_device_create()Samuel Mendoza-Jonas2016-09-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently discover_device_create() will search for existing discover devices by id to determine if a new device is required. However it is possible under some circumstances for distinct devices to have the same name. This is especially troublesome if the following network events are seen in network_handle_nlmsg(): - New interface, 'foo' with uuid x:x:x:x:x:x -> new discover device created with dev->device->id = 'foo' dev->uuid = x:x:x:x:x:x - New interface, 'foo' with uuid y:y:y:y:y:y -> existing device 'foo' found dev->uuid = y:y:y:y:y:y This can occur if an interface rename event arrives *after* an old name is reused, where temporarily Petitboot will see two distinct network interfaces with the same name. Now the two interfaces point to the same discover device, which can quickly result in a segfault if a 'remove' event occurs for one of the interfaces and the discover device is freed. To generally avoid this a 'uuid' parameter is added to discover_device_create(), which if present allows existing devices to be looked up by UUID rather than just their name. Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover/udev: Don't call udev_set_log_fn()Samuel Mendoza-Jonas2016-04-131-0/+4
| | | | | | | | | | As of libudev 218 udev_set_log_fn() is deprecated, causing a -Wdeprecated-declarations warning when building, and is otherwise a noop. Add a configure check for libudev, and only call udev_set_log_fn() if using a version older than 218. Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover/devmapper: Read device size from sysfsSamuel Mendoza-Jonas2016-04-081-3/+2
| | | | | | | | | | | | | If udev doesn't export the ID_PART_ENTRY_SIZE variable for a device we skip creating a snapshot for it. However in most cases the sysfs attribute which udev reads to find ID_PART_ENTRY_SIZE is still available. Therefore if we don't have access to ID_PART_ENTRY_SIZE try to find the size in sysfs directly. This allows us to create snapshots for devices which often don't have this udev variable set, such as software raid (md) devices and NVMe devices. Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
* discover: Fix dead code in udev_handle_cdrom_events()Samuel Mendoza-Jonas2015-12-181-3/+1
| | | | | | | | | The check against ddev->mounted to cause an eject action is logically impossible. Change it so a cdrom_eject() is called properly. Change the return value to 'true' for any action caused by DISK_EJECT_REQUEST - no further action is appropriate in this case Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
* Recognise storage devices on USB busSamuel Mendoza-Jonas2015-08-311-3/+9
| | | | | | | | Users may want to prioritise USB-attached storage devices differently to other devices. Detect if a device is USB-attached and add a new device type to identify it. Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
* discover/udev: Additional checks in udev_handle_block_addSamuel Mendoza-Jonas2015-08-181-3/+21
| | | | | | | | | | | | | - Several filesystem types can appear that we won't be able to mount. Instead of waiting to fail mounting them in device_handler_discover(), skip processing them at all. - Do not create dm-snapshots on top of raid arrays until we have a reliable way of determining the sector count for a md raid device. - Turn down the verbosity on skipping dm-devices. Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
* discover: Mount snapshots for all eligible disk devicesSamuel Mendoza-Jonas2015-08-061-2/+18
| | | | | | | | Device-mapper snapshots are created for all disk devices prior to being mounted. If explicit writes are made to the snapshot they are merged back to the disk once write access is released. Signed-off-by: Samuel Mendoza-Jonas <sam.mj@au1.ibm.com>
* discover/udev: NULL return from udev_enumerate_get_list_entry isn't an errorJeremy Kerr2014-04-171-5/+0
| | | | | | | | | | A NULL return can mean the list is empty; don't return a failure from this case. udev_list_entry_foreach does a check for a NULL entry, so we'll do the correct thing in the following loop. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/udev: fix double free on udev_init failuresJeremy Kerr2014-04-171-13/+13
| | | | | | | | | | | If the udev monitor or enumerate functions fail, we'll call the udev_unref and udev_monitor_unref functions twice: once in the cleanup path and once in the talloc destructor. This change moves all cleanup to the talloc destructor, so we only do the unrefs once. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* log: Allow runtime selection of 'debug' log levelJeremy Kerr2014-04-071-14/+9
| | | | | | | | | | | | | | | | | Currently, we need to compile with -DDEBUG to implement debug-level logging in the UIs and discover server. Since we may not be able to easily replace a system's petitboot binaries, this change introduces a -v|--verbose option to the discver server and ncurses UI, which enables debug at runtime. We also move some of the udev debug code out of an #ifdef DEBUG block. Since petitboot is generally started on boot, we also add a little infrastructure to pass -v to petitboot on certain system contitions: either petitboot.debug on the kernel command line, or a petitboot,debug? NVRAM property containing the value 'true'. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: add reinit pathJeremy Kerr2014-04-021-0/+6
| | | | | | | | | | | | | Currently, changes to settings doesn't take effect while the discover server is running. This means we need to reboot for any changes (eg, to network settings) to take effect. This change introduces a reinit path. Triggered by a configuration update, this will cause the device handler to drop all of its devices (and boot options), and restart the discovery process from the device sources. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: move device sources to the device handlerJeremy Kerr2014-04-021-8/+4
| | | | | | | | | | | | | | | | | | | | Currently, the pb-discover main() function initialises the device handler and the device sources. We want to eventually be able to re-init the device sources, which will be initiated by the handler. In this case, the handler will need references to the sources. This change moves the creation of the device sources to be internal to the handler. This way, the device handler gets a reference to everything, without having to pass pointers around in main(). We also remove the _destroy functions, as we handle everything through talloc destructors, as all sources are parented to the handler. We also change user_event_init and udev_init to take the handler as the first ('context') argument, to make them consistent with network_init. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/udev: duplicate devices aren't an errorJeremy Kerr2014-04-011-1/+1
| | | | | | | We don't need to error out of udev_handle_block_add if this is a duplicate UUID. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/udev: don't propagate non-fatal errors from udev_processJeremy Kerr2014-04-011-10/+3
| | | | | | | | | | | | Currently, we have a bug where non-zero return codes from udev_handle_dev_* cause the udev worker from deregistering from the waiter poll loop. This is becasue udev_process is propagating these errors, causing the deregistration. This change stops propagation of non-fatal errors, so we don't deregister. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Increase udev monitor buffer sizeJeremy Kerr2014-03-181-0/+11
| | | | | | | | | Since we may be enumerating devices after enabling the udev monitor, we may miss udev events that occur during this process. This change increases the default udev buffer size. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* udev: use pb_log for device SKIP messagesJeremy Kerr2014-03-141-5/+5
| | | | | | | We often want to find out why a device has been skipped, so include the SKIP messages at pb_log, which doesn't require a -DDEBUG build. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Use ID_FS_TYPE property for filesystem type detectionJeremy Kerr2014-03-141-0/+6
| | | | | | | | | | | | | | | | | | | | | | | Currently, we don't hand any -t option to mount, as we expect the mount binary to do autodetection of the filesystem type for us. Turns out this isn't great with busybox mount, (which we're likely to be using in petitboot builds), which implements "autodetection" by trying the mount() syscall with every fs type in /proc/filesystems, until one succeeds. We expect a lot of the mount calls to fail, as we currently try to mount everything (and abort discovery on devices that don't mount), including non-filesystem partitions. On a test machine with 560 block devices, and 37 entries in /proc/partitions, this results in around 20,000 calls to mount(). A better way would be to pass a -t option to mount. It turns out that udev uses libblkid to probe the filesystem type, which is available in the ID_FS_TYPE property. This change only attempts to mount filesystems with this property, and passes an explicit fstype to the mount binary. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/udev: Register udev monitor before enumerating devicesJeremy Kerr2014-03-071-20/+47
| | | | | | | | | | | | | | | | Currently, we enumerate udev devices before setting up our monitor. This means that we may lose devices that udev discovers after we start the enumeration, but before the monitor is registered. This change enables the monitor before enumeration, so we don't lose devices. We add a filter to the enumeration code to only parse completely initialised devices. This means we may need to handle change events as the main source of device notifications. We keep the existing CDROM event handler, but check for new devices and handle those as an add. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/udev: Separate block-specific udev discoveryJeremy Kerr2014-03-051-14/+33
| | | | | | | | | | We'd like to trigger network device discovery from udev code, but most of the device_add code path assumes block devices. This change adds a subsystem check, and moves the block-specific code to udev_handle_block_add. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/udev: Set device type for optical media correctlyJeremy Kerr2014-01-131-1/+1
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* configure: Use AC_GNU_SOURCEJeremy Kerr2013-12-181-1/+3
| | | | | | | Rather than #defining _GNU_SOURCE in our .c files, we can define this from config.h instead. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/udev: Use UUIDs for multipath checkJeremy Kerr2013-12-051-9/+14
| | | | | | Partitions will share a serial number. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Fix CDROM handlingJeremy Kerr2013-12-021-1/+80
| | | | | | | | | | | | | Currently, we don't handle CDROM devices well; we'll try to mount on boot, and not detect any media changes. Also, the default rules shipping with udev will put the CDROM tray into a locked state, blocking eject from working. This change adds a set of cdrom utility functions, which the udev code can use to properly initialise cdrom devices and handle eject and media change requests. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/udev: copy dev->device path from udev devnodeJeremy Kerr2013-12-021-1/+2
| | | | | | | We're seeing a use-after-free, as the udev path is freed before the discover device. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Change parsers to explicitly request configuration filesNeelesh Gupta2013-11-061-1/+1
| | | | | | | | | | | | | | | | | | | Add a new function parser_request_url() to read the data from configuration files present remotely. We deprecate iterate_parser_files() and download_config() functions along with the 'filenames' and 'method' members of the 'parser' structure so that individual parsers would now require to request the configuration files data from the parser code and doesn't necessarily export the list of configuration files. Add the support to handle incoming DHCP event, done by passing all the relevant environment variables of the udhcpc to the discover code. Also, update the pxe parser code to populate the list of configuration file names as per PXELINUX convention of fallback names using mac and ip addresses of the booting machine. Signed-off-by: Neelesh Gupta <neelegup@linux.vnet.ibm.com> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* logging: Clean up debug logsJeremy Kerr2013-11-011-10/+1
| | | | | | | We have quite a few pb_logs which should be pb_debug. This change moves developer-specific info to pb_debug. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/udev: dup property values returned from udevJeremy Kerr2013-10-091-2/+7
| | | | | | The property strings are managed by the udev code, so we need to strdup. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Check for devices with duplicate serial propertiesJeremy Kerr2013-09-241-0/+7
| | | | | | | | | If we have multipath devices present in the system, we'll end up with duplicate mounts, parse results and boot options. This change adds a check to see if we've encountered a device with this serial number previously. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Remove unnecessary event passingJeremy Kerr2013-09-191-57/+67
| | | | | | | | | | | | | | | Currently, we pass "events" between the udev, user-event and device-handler layers. These events all get sent through device_handler_event, then de-multiplexed to an appropriate handler, depending on their source. Instead, just export relevant device_handler functions, and have the (old) event sources call these functions directly. This also means we can include a lot more of the device hander code in the parser tests. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: Consolidate device path, name and ID.Jeremy Kerr2013-09-191-1/+2
| | | | | | | | | | | | This change cleans up our usage of device path, names and IDs. Device ID is the kernel name for the device. We also expose this through lookup_by_name. Device path is the path to the dev node (ie, always starts with /dev/), and is only used for mounting. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: populate udev device typesJeremy Kerr2013-09-181-0/+1
| | | | | | Now that we have device types, populate from the udev info. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* lib/waiter: Add timeout waitersJeremy Kerr2013-06-241-1/+1
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover: log cleanupJeremy Kerr2013-05-161-8/+1
| | | | | | | Remove some of the more noisy log messages, and add some information pertinent to device resolution events. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/udev: use devname (not devpath) for device IDsJeremy Kerr2013-05-151-1/+1
| | | | | | devnames are unique, and much shorter. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/udev: Setup event params from udev propertiesJeremy Kerr2013-05-091-16/+17
| | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* discover/udev: Don't print properties of skipped devicesJeremy Kerr2013-05-091-2/+2
| | | | | | This cleans up the log output a little. Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* udev: Revove use of udev_get_sys_pathGeoff Levand2013-05-051-1/+1
| | | | | | | libudev1 changed the symbol udev_get_sys_path to be private, so remove its use in petitboot. Signed-off-by: Geoff Levand <geoff@infradead.org>
* discover: Remove empty routine udev_triggerGeoff Levand2013-05-031-5/+0
| | | | | | | | With the switch of the discover server to use the libudev enumeration support the udev_trigger() routine has becone empty and is no longer needed. Signed-off-by: Geoff Levand <geoff@infradead.org>
* discover: Update udev routines to use libudevGeoff Levand2013-05-031-90/+238
| | | | | | | Support for 'RUN+="socket:' in udev rules files has been removed in udev version 183. Update the discover server to use libudev. Signed-off-by: Geoff Levand <geoff@infradead.org>
* discover: Rename struct udev to struct pb_udevGeoff Levand2013-05-031-9/+9
| | | | | | | To avoid symbol clashes with libudev, rename struct udev to struct pb_udev. No functional changes. Signed-off-by: Geoff Levand <geoff@infradead.org>
* waiter: Don't rely on global variables to keep waiter stateJeremy Kerr2013-04-101-2/+2
| | | | | | | | | Rather than defining the set of waiters (and pollfds) in waiter.c, add a struct waitset to contain these. A waitset is created with waitset_create, which is passed to the waiter_* functions. Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Signed-off-by: Geoff Levand <geoff@infradead.org>
* Add udevadm to pb_system_appsJeremy Kerr2013-03-051-1/+1
| | | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Signed-off-by: Geoff Levand <geoff@infradead.org>
* discover: Use pb_run_cmd rather than calling system()Jeremy Kerr2013-03-051-1/+11
| | | | | Signed-off-by: Jeremy Kerr <jk@ozlabs.org> Signed-off-by: Geoff Levand <geoff@infradead.org>
* pb-discover: Ignore ram, loop and no-name devicesGeoff Levand2012-03-261-5/+17
| | | | Signed-off-by: Geoff Levand <geoff@infradead.org>
* Zero automatic sockaddrGeoff Levand2012-03-261-0/+1
| | | | Signed-off-by: Geoff Levand <geoff@infradead.org>
* Add DEVPATH to udev_print_event()Geoff Levand2012-03-261-2/+6
| | | | Signed-off-by: Geoff Levand <geoff@infradead.org>
* Add '--action=add' to udevadm trigger commandGeoff Levand2012-02-241-1/+3
| | | | Signed-off-by: Geoff Levand <geoff@infradead.org>
* Make udev_event a generic eventGeoff Levand2009-06-301-88/+13
| | | | | | | | | | The struct udev_event can be used as a generic event, so rename it struct event and move it from udev.h into a new file event.h. Also, rename the emums UDEV_ACTION_ADD and UDEV_ACTION_REMOVE to ACTION_UDEV_ADD and ACTION_UDEV_REMOVE. Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* Udev log socket deviceGeoff Levand2009-06-301-0/+2
| | | | | | | To aid problem resolution log the udev socket device to the pb_log. Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
* Add udev triggerGeoff Levand2009-06-301-0/+10
| | | | | | | | Add a new routine udev_trigger() that requests a replay of system udev events. Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com> Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
OpenPOWER on IntegriCloud