summaryrefslogtreecommitdiff
path: root/blockd.c
Commit message (Collapse)AuthorAgeFilesLines
* blockd: restore device_move semanticsDaniel Golle2022-05-011-6/+4
| | | | | | | | | | | | | | Before commit 4963db4 block device were only removed and re-added in case of device_move() returning a non-zero value. Commit 4963db4 then (supposedly) accidentally inverted that logic and also (probably to work-around the problems resulting from the now inverted logic) limited this behavior to autofs mounts, leaving the autofs codepath in a semi- broken state. Restore the original semantics as of before commit 4963db4 to fully restore functionality for autofs mounts. Fixes: 4963db4 ("blockd: use uloop_process for calling /sbin/hotplug-call mount") Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* blockd: include missing libubox/utils.hDaniel Golle2021-08-251-0/+1
| | | | Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* blockd: fix resource leak discovered by coverity scanDaniel Golle2021-08-141-0/+3
| | | | | | Fixes Coverity CID 1463265 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* blockd: also report target in notificationsDaniel Golle2021-08-051-13/+32
| | | | | | | Useful to start/stop services triggered by mountpoints. See procd.sh procd_add_mount_trigger to make use of that. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* blockd: make most calls to 'block' asynchronousDaniel Golle2021-07-301-12/+27
| | | | | | | | | | | Don't wait for calls to 'block' to complete unless it's for an autofs event (which cannot be handled async). Use uloop for 'mount.ready' notificaion when startup has completed to avoid blocking in waitpid() while the 'block' process is calling back via ubus. This greatly reduces the amount of time blockd needs on boot. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* blockd: send mount.ready when startup has completedDaniel Golle2021-07-281-1/+4
| | | | | | Emmit mount.ready notification when 'block autofs start' has completed. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* blockd: fix length of timeout int passed to ioctlDaniel Golle2021-07-241-1/+1
| | | | | | | | AUTOFS_IOC_SETTIMEOUT expects a pointer to an 'unsigned long' which will result in out-of-bounds access when passing a pointer to an 'int'. Change type of timeout to 'unsigned long'. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* Revert "blockd: detect mountpoint of /dev/mapper/*"Daniel Golle2021-07-231-9/+0
| | | | | | This reverts commit 4d4dcfb33c5d9fa31c9916e106bee309ec7b4b01. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* blockd: create mountpoint parent folder if neededDaniel Golle2021-07-181-1/+9
| | | | Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* blockd: move to its own POSIX process groupDaniel Golle2021-07-151-0/+3
| | | | | | | | | | Not to be confused with cgroups, there are also POSIX process groups. They do matter when it comes to autofs, as all requests coming from the process group of the automounter itself will be ignored. Hence, if blockd runs in the same process group as init and all services, requests from services will be ignored. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* blockd: fix trigger nameDaniel Golle2021-07-151-1/+4
| | | | | | | Make it 'mount.add' instead of just 'add' which is more obvious when used with procd_add_raw_trigger. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* blockd: also send ubus notification on mount hotplugDaniel Golle2021-07-141-12/+34
| | | | | | | | | | Also sending a ubus notification on mount hotplug provides a useful shortcut for procd service triggers. As the /etc/hotplug.d/mount API for now doesn't have any users and also makes it hard to aggregate hotplug calls, we should consider removing it in favor of only using triggers on the block notifications in future. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* blockd: detect mountpoint of /dev/mapper/*Daniel Golle2021-07-141-2/+11
| | | | | | If a device cannot be found in /dev, also try /dev/mapper. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* blockd: add missing #define _GNU_SOURCEDaniel Golle2021-05-161-0/+1
| | | | | | asprintf requires _GNU_SOURCE to be defined. Set it. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* blockd: use allocated strings instead of fixed buffersDaniel Golle2021-05-161-12/+34
| | | | | | | | | device names can be pretty long when using LVM2, mount targets are user defined and can potentially also be of PATH_MAX length. Replace static buffers with dynamically allocated strings to avoid buffer overflow with too long device names or mount targets. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
* blockd: add optional "device" parameter to "info" ubus methodRafał Miłecki2020-05-061-21/+51
| | | | | | It allows getting info about specified device. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* block(d): always call hotplug.d "mount" scripts from blockdRafał Miłecki2020-05-061-0/+74
| | | | | | | | | | | | | | | | This resolves problem on boot with "mount" scripts being called too early to get blockd info. With this change "mount" scripts won't get called until blockd starts. On startup it requests all devices info and calls relevant scripts. This fixes samba36-hotplug package hotplug.d script. One downside of this change is handling "mount" evens on block restart or crash. On restart "add" actions will get executed for mounted / available (autofs) devices. On crash no events will be generated. Ref: http://lists.infradead.org/pipermail/openwrt-devel/2019-December/020886.html Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* blockd: use uloop_process for calling /sbin/hotplug-call mountRafał Miłecki2020-05-061-47/+85
| | | | | | | | | | | | | | | | | | As blockd uses uloop calling any script and using waitpid() can easily result in a lock. It's enough for script to use /bin/ubus to cause that. It's not an option to drop waitpid() as it's important to e.g. call mount scripts with ACTION=remove before unmounting devices. So solving this problem requires using uloop_process. Unfortunately this means: 1. Using callbacks making code slightly more complex 2. Dropping that nice devices_update_cb() With this change however hotplug.d "mount" scripts can safely call "ubus". Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* blockd: remove symlink linkpath file if it's a dir or linkRafał Miłecki2020-03-211-0/+7
| | | | | | | | Files like that can remain from using non-autofs mounting and can cause mounting errors after switching to autofs: blockd: failed to symlink /mnt/sda1->/tmp/run/blockd/sda1 Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* blockd: report "target" path as "mount" for autofs available mountsRafał Miłecki2020-03-211-0/+2
| | | | | | | | Devices handled with autofs should be seen as available even if currently unmounted. Mounting is handled on demand and transparently for users. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* blockd: print symlink error code and string messageRafał Miłecki2020-03-211-2/+2
| | | | | | | It may help understanding failure reason, e.g.: blockd: failed to symlink /mnt/sda1->/tmp/run/blockd/sda1 (17) - File exists Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* blockd: don't flush devices list on "hotplug" callRafał Miłecki2019-12-131-2/+0
| | | | | | | | The point of "hotplug" call is to add or remove a single entry to/from devices list. Using vlist_update() and vlist_flush() was clearing whole list (and leaving the last entry in case of adding a device). Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* blockd: fix vlist memory corruptionRafał Miłecki2019-12-131-1/+1
| | | | | | | | | vlist_add() expects key to point a persistent memory as it doesn't make its copy. Passing blob_attr of current message was resulting in undefined/random behavior including list corruption and possible crashes. Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* block(d): improve hotplug.d "mount" events for the autofsRafał Miłecki2018-12-281-0/+4
| | | | | | | | | | | | | | | | | | | | | | | So far - when using autofs - "add" and "remove" action events were triggered on every (un)mount. It wasn't very helpful when using autofs due to its nature. The point of blockd & autofs is to have block devices mounted on an access request. Its users should not care / know if it's currently mounted or not. Mounting should be handled transparently. To make that work it requires informing listeners whenever device: 1) Becomes *ready* for mounting (by triggering "add" action) 2) Becomes *unavailable* (by triggering "remove" action) The current mounting state is something that autofs & blockd should handle internally and should not notify listeners about. This is implemented by: 1) block generating events for non-autofs cases only (when (un)mounting) 2) blockd informing block when autofs resource becomes (un)available Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* blockd: unmount device explicitly when it disappearsRafał Miłecki2018-12-281-1/+12
| | | | | | | | | | | | To keep autofs behavior consistent blockd should request both: mounting and unmounting when needed. It's important as autofs-related actions may require slightly different handling. Without this patch: 1) autofs mounts were handled using TYPE_AUTOFS 2) autofs unmounts were handled using TYPE_HOTPLUG Signed-off-by: Rafał Miłecki <rafal@milecki.pl>
* blockd: don't reparse blob msg in the vlist callbacksRafał Miłecki2018-12-071-13/+3
| | | | | | | | | | | | ubus message is parsed in the block_hotplug() which fills all the struct device fields. Once that is done there is no need to parse original message again - it's enough to get required data from the struct. This also fixes handling messages with "autofs" set to 0. They were incorrectly interpreted due to the missing blobmsg_get_u32(). Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin <john@phrozen.org>
* blockd: don't unmount device when removing it from the listRafał Miłecki2018-12-061-24/+2
| | | | | | | | | | | | | | | | | | | | | | | | | Device gets removed from the list (vlist_delete()) when block calls "hotplug" method of blockd using ubus. Right after that block unmounts that device on its own. blockd shouldn't care about unmounting on its own for following reasons: 1) To avoid code/behavior duplication with block 2) To keep behavior consistent with mounting (blockd doesn't mount) 3) To allow implementing more features in block (e.g. hotplug.d events) To make unmounting the most reliable the plan is to have: 1) block receiving hotplug.d "block" subsystem events "remove" 2) blockd stopping reporting device (so we avoid new users & let existing ones realize mount can't be used anymore) 3) block notifying (through hotplug.d "mount" subsystem) all users about device being unmounted - that should stop all apps accessing it 4) block unmount device That should allow storage users stop accessing mount point & let block unmount device cleanly. Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin <john@phrozen.org>
* fstools: use EXIT_FAILURE when indicating error on exitMichael Heimpold2018-11-261-2/+2
| | | | | | | According to man page, using the EXIT_* macros is more portable than using plain integer values. Signed-off-by: Michael Heimpold <mhei@heimpold.de>
* blockd: add automounting supportJohn Crispin2017-02-271-0/+467
Signed-off-by: John Crispin <john@phrozen.org>