summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2020-12-08 22:36:42 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2020-12-10 12:26:19 +0900
commitb2d9e58f789fd691483e364d8a9fa5ee0c415c45 (patch)
tree4ebaca4ff1a866c1f1be7185a5da101a01e3b148
parent481f24d1f6ffb2535bce6531c2c67b7fdffdff56 (diff)
downloadsystemd-b2d9e58f789fd691483e364d8a9fa5ee0c415c45.tar.gz
udev: introduce log_device_uevent() helper function
And this drops duplicated check for seqnum and device action.
-rw-r--r--src/shared/udev-util.c14
-rw-r--r--src/shared/udev-util.h2
-rw-r--r--src/udev/udevd.c34
3 files changed, 20 insertions, 30 deletions
diff --git a/src/shared/udev-util.c b/src/shared/udev-util.c
index 030922eca9..411b1f704b 100644
--- a/src/shared/udev-util.c
+++ b/src/shared/udev-util.c
@@ -324,6 +324,20 @@ bool device_for_action(sd_device *dev, DeviceAction action) {
return a == action;
}
+void log_device_uevent(sd_device *device, const char *str) {
+ DeviceAction action = _DEVICE_ACTION_INVALID;
+ uint64_t seqnum = 0;
+
+ if (!DEBUG_LOGGING)
+ return;
+
+ (void) device_get_seqnum(device, &seqnum);
+ (void) device_get_action(device, &action);
+ log_device_debug(device, "%s%s(SEQNUM=%"PRIu64", ACTION=%s)",
+ strempty(str), isempty(str) ? "" : " ",
+ seqnum, strna(device_action_to_string(action)));
+}
+
int udev_rule_parse_value(char *str, char **ret_value, char **ret_endpos) {
char *i, *j;
int r;
diff --git a/src/shared/udev-util.h b/src/shared/udev-util.h
index 270861e55e..4e512cf754 100644
--- a/src/shared/udev-util.h
+++ b/src/shared/udev-util.h
@@ -33,4 +33,6 @@ int device_wait_for_devlink(const char *path, const char *subsystem, usec_t dead
int device_is_renaming(sd_device *dev);
bool device_for_action(sd_device *dev, DeviceAction action);
+void log_device_uevent(sd_device *device, const char *str);
+
int udev_rule_parse_value(char *str, char **ret_value, char **ret_endpos);
diff --git a/src/udev/udevd.c b/src/udev/udevd.c
index e65916cb1c..3961e76305 100644
--- a/src/udev/udevd.c
+++ b/src/udev/udevd.c
@@ -436,23 +436,12 @@ static int worker_mark_block_device_read_only(sd_device *dev) {
static int worker_process_device(Manager *manager, sd_device *dev) {
_cleanup_(udev_event_freep) UdevEvent *udev_event = NULL;
_cleanup_close_ int fd_lock = -1;
- DeviceAction action;
- uint64_t seqnum;
int r;
assert(manager);
assert(dev);
- r = device_get_seqnum(dev, &seqnum);
- if (r < 0)
- return log_device_debug_errno(dev, r, "Failed to get SEQNUM: %m");
-
- r = device_get_action(dev, &action);
- if (r < 0)
- return log_device_debug_errno(dev, r, "Failed to get ACTION: %m");
-
- log_device_debug(dev, "Processing device (SEQNUM=%"PRIu64", ACTION=%s)",
- seqnum, device_action_to_string(action));
+ log_device_uevent(dev, "Processing device");
udev_event = udev_event_new(dev, arg_exec_delay_usec, manager->rtnl);
if (!udev_event)
@@ -521,9 +510,7 @@ static int worker_process_device(Manager *manager, sd_device *dev) {
} else
(void) udev_watch_end(dev);
- log_device_debug(dev, "Device (SEQNUM=%"PRIu64", ACTION=%s) processed",
- seqnum, device_action_to_string(action));
-
+ log_device_uevent(dev, "Device processed");
return 0;
}
@@ -655,13 +642,7 @@ static void event_run(Manager *manager, struct event *event) {
assert(manager);
assert(event);
- if (DEBUG_LOGGING) {
- DeviceAction action;
-
- r = device_get_action(event->dev, &action);
- log_device_debug(event->dev, "Device (SEQNUM=%"PRIu64", ACTION=%s) ready for processing",
- event->seqnum, r >= 0 ? device_action_to_string(action) : "<unknown>");
- }
+ log_device_uevent(event->dev, "Device ready for processing");
HASHMAP_FOREACH(worker, manager->workers) {
if (worker->state != WORKER_IDLE)
@@ -704,7 +685,6 @@ static void event_run(Manager *manager, struct event *event) {
static int event_queue_insert(Manager *manager, sd_device *dev) {
_cleanup_(sd_device_unrefp) sd_device *clone = NULL;
struct event *event;
- DeviceAction action;
uint64_t seqnum;
int r;
@@ -719,11 +699,6 @@ static int event_queue_insert(Manager *manager, sd_device *dev) {
if (r < 0)
return r;
- /* Refuse devices do not have ACTION property. */
- r = device_get_action(dev, &action);
- if (r < 0)
- return r;
-
/* Save original device to restore the state on failures. */
r = device_shallow_clone(dev, &clone);
if (r < 0)
@@ -753,8 +728,7 @@ static int event_queue_insert(Manager *manager, sd_device *dev) {
LIST_APPEND(event, manager->events, event);
- log_device_debug(dev, "Device (SEQNUM=%"PRIu64", ACTION=%s) is queued",
- seqnum, device_action_to_string(action));
+ log_device_uevent(dev, "Device is queued");
return 0;
}