]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
udev: introduce log_device_uevent() helper function
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 8 Dec 2020 13:36:42 +0000 (22:36 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 10 Dec 2020 03:26:19 +0000 (12:26 +0900)
And this drops duplicated check for seqnum and device action.

src/shared/udev-util.c
src/shared/udev-util.h
src/udev/udevd.c

index 030922eca931b2a8db6eb17fe5eeb9bed642625a..411b1f704bc038de94d2c7a6291e178b8374f8c1 100644 (file)
@@ -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;
index 270861e55edc97663af1387f4ad6bcbaf4fb7067..4e512cf754ec899f15421bc89e5c591085b8e8a2 100644 (file)
@@ -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);
index e65916cb1c0e24ba058d88372dbbcb632922b4c0..3961e763059a92a2120a6d1cf26f42df702532d6 100644 (file)
@@ -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;
 }