sd-device: introduce database version and save it in udev database V field

This commit is contained in:
Yu Watanabe 2020-11-26 06:23:14 +09:00
parent 9e25cca130
commit 58b30ada0b
3 changed files with 20 additions and 0 deletions

View File

@ -8,9 +8,19 @@
#include "set.h"
#include "time-util.h"
#define LATEST_UDEV_DATABASE_VERSION 1
struct sd_device {
unsigned n_ref;
/* The database version indicates the supported features by the udev database.
* This is saved and parsed in V field.
*
* 0: None of the following features are supported (systemd version <= 246).
* 1: The current tags (Q) and the database version (V) features are implemented (>= 247).
*/
unsigned database_version;
int watch_handle;
sd_device *parent;

View File

@ -948,6 +948,10 @@ int device_update_db(sd_device *device) {
SET_FOREACH(tag, device->current_tags)
fprintf(f, "Q:%s\n", tag); /* Current tag */
/* Always write the latest database version here, instead of the value stored in
* device->database_version, as which may be 0. */
fputs("V:" STRINGIFY(LATEST_UDEV_DATABASE_VERSION) "\n", f);
}
r = fflush_and_check(f);

View File

@ -1204,6 +1204,12 @@ static int handle_db_line(sd_device *device, char key, const char *value) {
if (r < 0)
return r;
break;
case 'V':
r = safe_atou(value, &device->database_version);
if (r < 0)
return r;
break;
default:
log_device_debug(device, "sd-device: Unknown key '%c' in device db, ignoring", key);