2 This file is part of systemd.
4 Copyright 2010 Lennart Poettering
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
21 #include <sys/epoll.h>
25 #include "alloc-util.h"
26 #include "dbus-device.h"
29 #include "parse-util.h"
30 #include "path-util.h"
31 #include "stat-util.h"
32 #include "string-util.h"
34 #include "udev-util.h"
35 #include "unit-name.h"
38 static const UnitActiveState state_translation_table
[_DEVICE_STATE_MAX
] = {
39 [DEVICE_DEAD
] = UNIT_INACTIVE
,
40 [DEVICE_TENTATIVE
] = UNIT_ACTIVATING
,
41 [DEVICE_PLUGGED
] = UNIT_ACTIVE
,
44 static int device_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
);
46 static void device_unset_sysfs(Device
*d
) {
55 /* Remove this unit from the chain of devices which share the
57 devices
= UNIT(d
)->manager
->devices_by_sysfs
;
58 first
= hashmap_get(devices
, d
->sysfs
);
59 LIST_REMOVE(same_sysfs
, first
, d
);
62 hashmap_remove_and_replace(devices
, d
->sysfs
, first
->sysfs
, first
);
64 hashmap_remove(devices
, d
->sysfs
);
66 d
->sysfs
= mfree(d
->sysfs
);
69 static int device_set_sysfs(Device
*d
, const char *sysfs
) {
76 if (streq_ptr(d
->sysfs
, sysfs
))
79 r
= hashmap_ensure_allocated(&UNIT(d
)->manager
->devices_by_sysfs
, &string_hash_ops
);
87 device_unset_sysfs(d
);
89 first
= hashmap_get(UNIT(d
)->manager
->devices_by_sysfs
, sysfs
);
90 LIST_PREPEND(same_sysfs
, first
, d
);
92 r
= hashmap_replace(UNIT(d
)->manager
->devices_by_sysfs
, copy
, first
);
94 LIST_REMOVE(same_sysfs
, first
, d
);
104 static void device_init(Unit
*u
) {
105 Device
*d
= DEVICE(u
);
108 assert(UNIT(d
)->load_state
== UNIT_STUB
);
110 /* In contrast to all other unit types we timeout jobs waiting
111 * for devices by default. This is because they otherwise wait
112 * indefinitely for plugged in devices, something which cannot
113 * happen for the other units since their operations time out
115 u
->job_running_timeout
= u
->manager
->default_timeout_start_usec
;
117 u
->ignore_on_isolate
= true;
120 static void device_done(Unit
*u
) {
121 Device
*d
= DEVICE(u
);
125 device_unset_sysfs(d
);
128 static void device_set_state(Device
*d
, DeviceState state
) {
129 DeviceState old_state
;
132 old_state
= d
->state
;
135 if (state
!= old_state
)
136 log_unit_debug(UNIT(d
), "Changed %s -> %s", device_state_to_string(old_state
), device_state_to_string(state
));
138 unit_notify(UNIT(d
), state_translation_table
[old_state
], state_translation_table
[state
], true);
141 static int device_coldplug(Unit
*u
) {
142 Device
*d
= DEVICE(u
);
145 assert(d
->state
== DEVICE_DEAD
);
147 if (d
->found
& DEVICE_FOUND_UDEV
)
148 /* If udev says the device is around, it's around */
149 device_set_state(d
, DEVICE_PLUGGED
);
150 else if (d
->found
!= DEVICE_NOT_FOUND
&& d
->deserialized_state
!= DEVICE_PLUGGED
)
151 /* If a device is found in /proc/self/mountinfo or
152 * /proc/swaps, and was not yet announced via udev,
153 * it's "tentatively" around. */
154 device_set_state(d
, DEVICE_TENTATIVE
);
159 static int device_serialize(Unit
*u
, FILE *f
, FDSet
*fds
) {
160 Device
*d
= DEVICE(u
);
166 unit_serialize_item(u
, f
, "state", device_state_to_string(d
->state
));
171 static int device_deserialize_item(Unit
*u
, const char *key
, const char *value
, FDSet
*fds
) {
172 Device
*d
= DEVICE(u
);
179 if (streq(key
, "state")) {
182 state
= device_state_from_string(value
);
184 log_unit_debug(u
, "Failed to parse state value: %s", value
);
186 d
->deserialized_state
= state
;
188 log_unit_debug(u
, "Unknown serialization key: %s", key
);
193 static void device_dump(Unit
*u
, FILE *f
, const char *prefix
) {
194 Device
*d
= DEVICE(u
);
199 "%sDevice State: %s\n"
200 "%sSysfs Path: %s\n",
201 prefix
, device_state_to_string(d
->state
),
202 prefix
, strna(d
->sysfs
));
205 _pure_
static UnitActiveState
device_active_state(Unit
*u
) {
208 return state_translation_table
[DEVICE(u
)->state
];
211 _pure_
static const char *device_sub_state_to_string(Unit
*u
) {
214 return device_state_to_string(DEVICE(u
)->state
);
217 static int device_update_description(Unit
*u
, struct udev_device
*dev
, const char *path
) {
225 model
= udev_device_get_property_value(dev
, "ID_MODEL_FROM_DATABASE");
227 model
= udev_device_get_property_value(dev
, "ID_MODEL");
232 /* Try to concatenate the device model string with a label, if there is one */
233 label
= udev_device_get_property_value(dev
, "ID_FS_LABEL");
235 label
= udev_device_get_property_value(dev
, "ID_PART_ENTRY_NAME");
237 label
= udev_device_get_property_value(dev
, "ID_PART_ENTRY_NUMBER");
240 _cleanup_free_
char *j
;
242 j
= strjoin(model
, " ", label
);
244 r
= unit_set_description(u
, j
);
248 r
= unit_set_description(u
, model
);
250 r
= unit_set_description(u
, path
);
253 log_unit_error_errno(u
, r
, "Failed to set device description: %m");
258 static int device_add_udev_wants(Unit
*u
, struct udev_device
*dev
) {
259 const char *wants
, *property
;
265 property
= MANAGER_IS_USER(u
->manager
) ? "SYSTEMD_USER_WANTS" : "SYSTEMD_WANTS";
267 wants
= udev_device_get_property_value(dev
, property
);
272 _cleanup_free_
char *word
= NULL
, *k
= NULL
;
274 r
= extract_first_word(&wants
, &word
, NULL
, EXTRACT_QUOTES
);
280 return log_unit_error_errno(u
, r
, "Failed to parse property %s with value %s: %m", property
, wants
);
282 if (unit_name_is_valid(word
, UNIT_NAME_TEMPLATE
) && DEVICE(u
)->sysfs
) {
283 _cleanup_free_
char *escaped
= NULL
;
285 /* If the unit name is specified as template, then automatically fill in the sysfs path of the
286 * device as instance name, properly escaped. */
288 r
= unit_name_path_escape(DEVICE(u
)->sysfs
, &escaped
);
290 return log_unit_error_errno(u
, r
, "Failed to escape %s: %m", DEVICE(u
)->sysfs
);
292 r
= unit_name_replace_instance(word
, escaped
, &k
);
294 return log_unit_error_errno(u
, r
, "Failed to build %s instance of template %s: %m", escaped
, word
);
296 /* If this is not a template, then let's mangle it so, that it becomes a valid unit name. */
298 r
= unit_name_mangle(word
, UNIT_NAME_NOGLOB
, &k
);
300 return log_unit_error_errno(u
, r
, "Failed to mangle unit name \"%s\": %m", word
);
303 r
= unit_add_dependency_by_name(u
, UNIT_WANTS
, k
, NULL
, true, UNIT_DEPENDENCY_UDEV
);
305 return log_unit_error_errno(u
, r
, "Failed to add Wants= dependency: %m");
309 static bool device_is_bound_by_mounts(Device
*d
, struct udev_device
*dev
) {
310 const char *bound_by
;
316 bound_by
= udev_device_get_property_value(dev
, "SYSTEMD_MOUNT_DEVICE_BOUND");
318 r
= parse_boolean(bound_by
);
320 log_warning_errno(r
, "Failed to parse SYSTEMD_MOUNT_DEVICE_BOUND='%s' udev property of %s, ignoring: %m", bound_by
, strna(d
->sysfs
));
322 d
->bind_mounts
= r
> 0;
324 d
->bind_mounts
= false;
326 return d
->bind_mounts
;
329 static int device_upgrade_mount_deps(Unit
*u
) {
335 /* Let's upgrade Requires= to BindsTo= on us. (Used when SYSTEMD_MOUNT_DEVICE_BOUND is set) */
337 HASHMAP_FOREACH_KEY(v
, other
, u
->dependencies
[UNIT_REQUIRED_BY
], i
) {
338 if (other
->type
!= UNIT_MOUNT
)
341 r
= unit_add_dependency(other
, UNIT_BINDS_TO
, u
, true, UNIT_DEPENDENCY_UDEV
);
348 static int device_setup_unit(Manager
*m
, struct udev_device
*dev
, const char *path
, bool main
) {
349 _cleanup_free_
char *e
= NULL
;
350 const char *sysfs
= NULL
;
359 sysfs
= udev_device_get_syspath(dev
);
364 r
= unit_name_from_path(path
, ".device", &e
);
366 return log_error_errno(r
, "Failed to generate unit name from device path: %m");
368 u
= manager_get_unit(m
, e
);
370 /* The device unit can still be present even if the device was unplugged: a mount unit can reference it hence
371 * preventing the GC to have garbaged it. That's desired since the device unit may have a dependency on the
372 * mount unit which was added during the loading of the later. */
373 if (dev
&& DEVICE(u
)->state
== DEVICE_PLUGGED
) {
375 /* This unit is in plugged state: we're sure it's attached to a device. */
376 if (!path_equal(DEVICE(u
)->sysfs
, sysfs
)) {
377 log_unit_debug(u
, "Dev %s appeared twice with different sysfs paths %s and %s",
378 e
, DEVICE(u
)->sysfs
, sysfs
);
385 /* Let's remove all dependencies generated due to udev properties. We'll readd whatever is configured
387 unit_remove_dependencies(u
, UNIT_DEPENDENCY_UDEV
);
391 r
= unit_new_for_name(m
, sizeof(Device
), e
, &u
);
395 unit_add_to_load_queue(u
);
398 /* If this was created via some dependency and has not
399 * actually been seen yet ->sysfs will not be
400 * initialized. Hence initialize it if necessary. */
402 r
= device_set_sysfs(DEVICE(u
), sysfs
);
406 (void) device_update_description(u
, dev
, path
);
408 /* The additional systemd udev properties we only interpret
409 * for the main object */
411 (void) device_add_udev_wants(u
, dev
);
414 /* So the user wants the mount units to be bound to the device but a mount unit might has been seen by systemd
415 * before the device appears on its radar. In this case the device unit is partially initialized and includes
416 * the deps on the mount unit but at that time the "bind mounts" flag wasn't not present. Fix this up now. */
417 if (dev
&& device_is_bound_by_mounts(DEVICE(u
), dev
))
418 device_upgrade_mount_deps(u
);
420 /* Note that this won't dispatch the load queue, the caller has to do that if needed and appropriate */
422 unit_add_to_dbus_queue(u
);
426 log_unit_warning_errno(u
, r
, "Failed to set up device unit: %m");
434 static int device_process_new(Manager
*m
, struct udev_device
*dev
) {
435 const char *sysfs
, *dn
, *alias
;
436 struct udev_list_entry
*item
= NULL
, *first
= NULL
;
441 sysfs
= udev_device_get_syspath(dev
);
445 /* Add the main unit named after the sysfs path */
446 r
= device_setup_unit(m
, dev
, sysfs
, true);
450 /* Add an additional unit for the device node */
451 dn
= udev_device_get_devnode(dev
);
453 (void) device_setup_unit(m
, dev
, dn
, false);
455 /* Add additional units for all symlinks */
456 first
= udev_device_get_devlinks_list_entry(dev
);
457 udev_list_entry_foreach(item
, first
) {
461 /* Don't bother with the /dev/block links */
462 p
= udev_list_entry_get_name(item
);
464 if (path_startswith(p
, "/dev/block/") ||
465 path_startswith(p
, "/dev/char/"))
468 /* Verify that the symlink in the FS actually belongs
469 * to this device. This is useful to deal with
470 * conflicting devices, e.g. when two disks want the
471 * same /dev/disk/by-label/xxx link because they have
472 * the same label. We want to make sure that the same
473 * device that won the symlink wins in systemd, so we
474 * check the device node major/minor */
475 if (stat(p
, &st
) >= 0)
476 if ((!S_ISBLK(st
.st_mode
) && !S_ISCHR(st
.st_mode
)) ||
477 st
.st_rdev
!= udev_device_get_devnum(dev
))
480 (void) device_setup_unit(m
, dev
, p
, false);
483 /* Add additional units for all explicitly configured
485 alias
= udev_device_get_property_value(dev
, "SYSTEMD_ALIAS");
487 _cleanup_free_
char *word
= NULL
;
489 r
= extract_first_word(&alias
, &word
, NULL
, EXTRACT_QUOTES
);
495 return log_warning_errno(r
, "Failed to add parse SYSTEMD_ALIAS for %s: %m", sysfs
);
497 if (path_is_absolute(word
))
498 (void) device_setup_unit(m
, dev
, word
, false);
500 log_warning("SYSTEMD_ALIAS for %s is not an absolute path, ignoring: %s", sysfs
, word
);
504 static void device_update_found_one(Device
*d
, bool add
, DeviceFound found
, bool now
) {
505 DeviceFound n
, previous
;
509 n
= add
? (d
->found
| found
) : (d
->found
& ~found
);
519 /* Didn't exist before, but does now? if so, generate a new invocation ID for it */
520 if (previous
== DEVICE_NOT_FOUND
&& d
->found
!= DEVICE_NOT_FOUND
)
521 (void) unit_acquire_invocation_id(UNIT(d
));
523 if (d
->found
& DEVICE_FOUND_UDEV
)
524 /* When the device is known to udev we consider it
526 device_set_state(d
, DEVICE_PLUGGED
);
527 else if (d
->found
!= DEVICE_NOT_FOUND
&& (previous
& DEVICE_FOUND_UDEV
) == 0)
528 /* If the device has not been seen by udev yet, but is
529 * now referenced by the kernel, then we assume the
530 * kernel knows it now, and udev might soon too. */
531 device_set_state(d
, DEVICE_TENTATIVE
);
533 /* If nobody sees the device, or if the device was
534 * previously seen by udev and now is only referenced
535 * from the kernel, then we consider the device is
536 * gone, the kernel just hasn't noticed it yet. */
538 device_set_state(d
, DEVICE_DEAD
);
539 device_unset_sysfs(d
);
544 static int device_update_found_by_sysfs(Manager
*m
, const char *sysfs
, bool add
, DeviceFound found
, bool now
) {
550 if (found
== DEVICE_NOT_FOUND
)
553 l
= hashmap_get(m
->devices_by_sysfs
, sysfs
);
554 LIST_FOREACH_SAFE(same_sysfs
, d
, n
, l
)
555 device_update_found_one(d
, add
, found
, now
);
560 static int device_update_found_by_name(Manager
*m
, const char *path
, bool add
, DeviceFound found
, bool now
) {
561 _cleanup_free_
char *e
= NULL
;
568 if (found
== DEVICE_NOT_FOUND
)
571 r
= unit_name_from_path(path
, ".device", &e
);
573 return log_error_errno(r
, "Failed to generate unit name from device path: %m");
575 u
= manager_get_unit(m
, e
);
579 device_update_found_one(DEVICE(u
), add
, found
, now
);
583 static bool device_is_ready(struct udev_device
*dev
) {
588 ready
= udev_device_get_property_value(dev
, "SYSTEMD_READY");
592 return parse_boolean(ready
) != 0;
595 static Unit
*device_following(Unit
*u
) {
596 Device
*d
= DEVICE(u
);
597 Device
*other
, *first
= NULL
;
601 if (startswith(u
->id
, "sys-"))
604 /* Make everybody follow the unit that's named after the sysfs path */
605 for (other
= d
->same_sysfs_next
; other
; other
= other
->same_sysfs_next
)
606 if (startswith(UNIT(other
)->id
, "sys-"))
609 for (other
= d
->same_sysfs_prev
; other
; other
= other
->same_sysfs_prev
) {
610 if (startswith(UNIT(other
)->id
, "sys-"))
619 static int device_following_set(Unit
*u
, Set
**_set
) {
620 Device
*d
= DEVICE(u
), *other
;
627 if (LIST_JUST_US(same_sysfs
, d
)) {
636 LIST_FOREACH_AFTER(same_sysfs
, other
, d
) {
637 r
= set_put(set
, other
);
642 LIST_FOREACH_BEFORE(same_sysfs
, other
, d
) {
643 r
= set_put(set
, other
);
656 static void device_shutdown(Manager
*m
) {
659 m
->udev_event_source
= sd_event_source_unref(m
->udev_event_source
);
661 if (m
->udev_monitor
) {
662 udev_monitor_unref(m
->udev_monitor
);
663 m
->udev_monitor
= NULL
;
666 m
->devices_by_sysfs
= hashmap_free(m
->devices_by_sysfs
);
669 static void device_enumerate(Manager
*m
) {
670 _cleanup_udev_enumerate_unref_
struct udev_enumerate
*e
= NULL
;
671 struct udev_list_entry
*item
= NULL
, *first
= NULL
;
676 if (!m
->udev_monitor
) {
677 m
->udev_monitor
= udev_monitor_new_from_netlink(m
->udev
, "udev");
678 if (!m
->udev_monitor
) {
683 /* This will fail if we are unprivileged, but that
684 * should not matter much, as user instances won't run
686 (void) udev_monitor_set_receive_buffer_size(m
->udev_monitor
, 128*1024*1024);
688 r
= udev_monitor_filter_add_match_tag(m
->udev_monitor
, "systemd");
690 log_error_errno(r
, "Failed to add udev tag match: %m");
694 r
= udev_monitor_enable_receiving(m
->udev_monitor
);
696 log_error_errno(r
, "Failed to enable udev event reception: %m");
700 r
= sd_event_add_io(m
->event
, &m
->udev_event_source
, udev_monitor_get_fd(m
->udev_monitor
), EPOLLIN
, device_dispatch_io
, m
);
702 log_error_errno(r
, "Failed to watch udev file descriptor: %m");
706 (void) sd_event_source_set_description(m
->udev_event_source
, "device");
709 e
= udev_enumerate_new(m
->udev
);
715 r
= udev_enumerate_add_match_tag(e
, "systemd");
717 log_error_errno(r
, "Failed to create udev tag enumeration: %m");
721 r
= udev_enumerate_add_match_is_initialized(e
);
723 log_error_errno(r
, "Failed to install initialization match into enumeration: %m");
727 r
= udev_enumerate_scan_devices(e
);
729 log_error_errno(r
, "Failed to enumerate devices: %m");
733 first
= udev_enumerate_get_list_entry(e
);
734 udev_list_entry_foreach(item
, first
) {
735 _cleanup_udev_device_unref_
struct udev_device
*dev
= NULL
;
738 sysfs
= udev_list_entry_get_name(item
);
740 dev
= udev_device_new_from_syspath(m
->udev
, sysfs
);
746 if (!device_is_ready(dev
))
749 (void) device_process_new(m
, dev
);
751 device_update_found_by_sysfs(m
, sysfs
, true, DEVICE_FOUND_UDEV
, false);
760 static int device_dispatch_io(sd_event_source
*source
, int fd
, uint32_t revents
, void *userdata
) {
761 _cleanup_udev_device_unref_
struct udev_device
*dev
= NULL
;
762 Manager
*m
= userdata
;
763 const char *action
, *sysfs
;
768 if (revents
!= EPOLLIN
) {
769 static RATELIMIT_DEFINE(limit
, 10*USEC_PER_SEC
, 5);
771 if (!ratelimit_test(&limit
))
772 log_error_errno(errno
, "Failed to get udev event: %m");
773 if (!(revents
& EPOLLIN
))
778 * libudev might filter-out devices which pass the bloom
779 * filter, so getting NULL here is not necessarily an error.
781 dev
= udev_monitor_receive_device(m
->udev_monitor
);
785 sysfs
= udev_device_get_syspath(dev
);
787 log_error("Failed to get udev sys path.");
791 action
= udev_device_get_action(dev
);
793 log_error("Failed to get udev action string.");
797 if (streq(action
, "change")) {
798 _cleanup_free_
char *e
= NULL
;
801 r
= unit_name_from_path(sysfs
, ".device", &e
);
803 log_error_errno(r
, "Failed to generate unit name from device path: %m");
805 u
= manager_get_unit(m
, e
);
806 if (u
&& UNIT_VTABLE(u
)->active_state(u
) == UNIT_ACTIVE
) {
807 r
= manager_propagate_reload(m
, u
, JOB_REPLACE
, NULL
);
809 log_error_errno(r
, "Failed to propagate reload: %m");
814 /* A change event can signal that a device is becoming ready, in particular if
815 * the device is using the SYSTEMD_READY logic in udev
816 * so we need to reach the else block of the follwing if, even for change events */
817 if (streq(action
, "remove")) {
818 r
= swap_process_device_remove(m
, dev
);
820 log_error_errno(r
, "Failed to process swap device remove event: %m");
822 /* If we get notified that a device was removed by
823 * udev, then it's completely gone, hence unset all
825 device_update_found_by_sysfs(m
, sysfs
, false, DEVICE_FOUND_UDEV
|DEVICE_FOUND_MOUNT
|DEVICE_FOUND_SWAP
, true);
827 } else if (device_is_ready(dev
)) {
829 (void) device_process_new(m
, dev
);
831 r
= swap_process_device_new(m
, dev
);
833 log_error_errno(r
, "Failed to process swap device new event: %m");
835 manager_dispatch_load_queue(m
);
837 /* The device is found now, set the udev found bit */
838 device_update_found_by_sysfs(m
, sysfs
, true, DEVICE_FOUND_UDEV
, true);
841 /* The device is nominally around, but not ready for
842 * us. Hence unset the udev bit, but leave the rest
845 device_update_found_by_sysfs(m
, sysfs
, false, DEVICE_FOUND_UDEV
, true);
851 static bool device_supported(void) {
852 static int read_only
= -1;
854 /* If /sys is read-only we don't support device units, and any
855 * attempts to start one should fail immediately. */
858 read_only
= path_is_read_only_fs("/sys");
860 return read_only
<= 0;
863 int device_found_node(Manager
*m
, const char *node
, bool add
, DeviceFound found
, bool now
) {
864 _cleanup_udev_device_unref_
struct udev_device
*dev
= NULL
;
870 if (!device_supported())
873 /* This is called whenever we find a device referenced in
874 * /proc/swaps or /proc/self/mounts. Such a device might be
875 * mounted/enabled at a time where udev has not finished
876 * probing it yet, and we thus haven't learned about it
877 * yet. In this case we will set the device unit to
878 * "tentative" state. */
881 if (!path_startswith(node
, "/dev"))
884 /* We make an extra check here, if the device node
885 * actually exists. If it's missing, then this is an
886 * indication that device was unplugged but is still
887 * referenced in /proc/swaps or
888 * /proc/self/mountinfo. Note that this check doesn't
889 * really cover all cases where a device might be gone
890 * away, since drives that can have a medium inserted
891 * will still have a device node even when the medium
894 if (stat(node
, &st
) >= 0) {
895 if (!S_ISBLK(st
.st_mode
) && !S_ISCHR(st
.st_mode
))
898 dev
= udev_device_new_from_devnum(m
->udev
, S_ISBLK(st
.st_mode
) ? 'b' : 'c', st
.st_rdev
);
899 if (!dev
&& errno
!= ENOENT
)
900 return log_error_errno(errno
, "Failed to get udev device from devnum %u:%u: %m", major(st
.st_rdev
), minor(st
.st_rdev
));
902 } else if (errno
!= ENOENT
)
903 return log_error_errno(errno
, "Failed to stat device node file %s: %m", node
);
905 /* If the device is known in the kernel and newly
906 * appeared, then we'll create a device unit for it,
907 * under the name referenced in /proc/swaps or
908 * /proc/self/mountinfo. */
910 (void) device_setup_unit(m
, dev
, node
, false);
913 /* Update the device unit's state, should it exist */
914 return device_update_found_by_name(m
, node
, add
, found
, now
);
917 bool device_shall_be_bound_by(Unit
*device
, Unit
*u
) {
919 if (u
->type
!= UNIT_MOUNT
)
922 return DEVICE(device
)->bind_mounts
;
925 const UnitVTable device_vtable
= {
926 .object_size
= sizeof(Device
),
936 .load
= unit_load_fragment_and_dropin_optional
,
938 .coldplug
= device_coldplug
,
940 .serialize
= device_serialize
,
941 .deserialize_item
= device_deserialize_item
,
945 .active_state
= device_active_state
,
946 .sub_state_to_string
= device_sub_state_to_string
,
948 .bus_vtable
= bus_device_vtable
,
950 .following
= device_following
,
951 .following_set
= device_following_set
,
953 .enumerate
= device_enumerate
,
954 .shutdown
= device_shutdown
,
955 .supported
= device_supported
,
957 .status_message_formats
= {
958 .starting_stopping
= {
959 [0] = "Expecting device %s...",
961 .finished_start_job
= {
962 [JOB_DONE
] = "Found device %s.",
963 [JOB_TIMEOUT
] = "Timed out waiting for device %s.",