udev: introduce log_device_uevent() helper function
And this drops duplicated check for seqnum and device action.
This commit is contained in:
parent
481f24d1f6
commit
b2d9e58f78
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue