#include "parse-util.h"
#include "path-util.h"
#include "stat-util.h"
+#include "string-table.h"
#include "string-util.h"
#include "swap.h"
#include "udev-util.h"
assert(d);
assert(d->state == DEVICE_DEAD);
+ /* This should happen only when we reexecute PID1 from an old version
+ * which didn't serialize d->found. In this case simply assume that the
+ * device was in plugged state right before we started reexecuting which
+ * might be a wrong assumption. */
+ if (d->found == DEVICE_FOUND_UDEV_DB)
+ d->found = DEVICE_FOUND_UDEV;
+
if (d->found & DEVICE_FOUND_UDEV)
/* If udev says the device is around, it's around */
device_set_state(d, DEVICE_PLUGGED);
assert(fds);
unit_serialize_item(u, f, "state", device_state_to_string(d->state));
+ unit_serialize_item(u, f, "found", device_found_to_string(d->found));
return 0;
}
log_unit_debug(u, "Failed to parse state value: %s", value);
else
d->deserialized_state = state;
+
+ } else if (streq(key, "found")) {
+ DeviceFound found;
+
+ found = device_found_from_string(value);
+ if (found < 0)
+ log_unit_debug(u, "Failed to parse found value: %s", value);
+ else
+ d->found = found;
+
} else
log_unit_debug(u, "Unknown serialization key: %s", key);
(void) device_process_new(m, dev);
- device_update_found_by_sysfs(m, sysfs, true, DEVICE_FOUND_UDEV, false);
+ device_update_found_by_sysfs(m, sysfs, true, DEVICE_FOUND_UDEV_DB, false);
}
return;
return DEVICE(device)->bind_mounts;
}
+static const char* const device_found_table[] = {
+ [DEVICE_NOT_FOUND] = "not-found",
+ [DEVICE_FOUND_UDEV] = "found-udev",
+ [DEVICE_FOUND_UDEV_DB] = "found-udev-db",
+ [DEVICE_FOUND_MOUNT] = "found-mount",
+ [DEVICE_FOUND_SWAP] = "found-swap",
+};
+
+DEFINE_STRING_TABLE_LOOKUP(device_found, DeviceFound);
+
const UnitVTable device_vtable = {
.object_size = sizeof(Device),
.sections =
typedef struct Device Device;
typedef enum DeviceFound {
- DEVICE_NOT_FOUND = 0,
- DEVICE_FOUND_UDEV = 1,
- DEVICE_FOUND_MOUNT = 2,
- DEVICE_FOUND_SWAP = 4,
+ DEVICE_NOT_FOUND = 0,
+ DEVICE_FOUND_UDEV = 1 << 1,
+ DEVICE_FOUND_UDEV_DB = 1 << 2,
+ DEVICE_FOUND_MOUNT = 1 << 3,
+ DEVICE_FOUND_SWAP = 1 << 4,
} DeviceFound;
struct Device {
int device_found_node(Manager *m, const char *node, bool add, DeviceFound found, bool now);
bool device_shall_be_bound_by(Unit *device, Unit *u);
+
+const char *device_found_to_string(DeviceFound f) _const_;
+DeviceFound device_found_from_string(const char *s) _pure_;