]> sourceware.org Git - lvm2.git/commitdiff
config: use timestamp with nanosecond precision
authorZdenek Kabelac <zkabelac@redhat.com>
Wed, 18 Mar 2015 09:59:41 +0000 (10:59 +0100)
committerZdenek Kabelac <zkabelac@redhat.com>
Wed, 18 Mar 2015 12:42:56 +0000 (13:42 +0100)
Since kernel 2.6 we can use more precise timestamping,
so e.g. we could better recognize configs are slightly
older then generated .cache file.

WHATS_NEW
lib/commands/toolcontext.c
lib/config/config.c
lib/config/config.h
lib/filters/filter-persistent.c

index 0ce81fb118ca230efe8936687a819ef334b5f614..51307cbf9f8740d116fba49d2f98e9cc7b0106ca 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
 Version 2.02.118 - 
 =================================
+  Measure configuration timestamps with nanoseconds when available.
   Disable lvchange of major and minor of pool LVs.
   Fix pvscan --cache to not scan and read ignored metadata areas on PVs.
   Add After=iscsi-shutdown.service to blk-availability.service systemd unit.
index 25d9826342d3ae9a481e28257153d98839a87e55..54dcf86db45a6c169796b10647e8ab2b8e259d65 100644 (file)
@@ -1140,6 +1140,7 @@ static int _init_filters(struct cmd_context *cmd, unsigned load_persistent_cache
        struct dev_filter *filter = NULL, *filter_components[2] = {0};
        struct stat st;
        const struct dm_config_node *cn;
+       struct timespec ts, cts;
 
        cmd->dump_filter = 0;
 
@@ -1212,11 +1213,14 @@ static int _init_filters(struct cmd_context *cmd, unsigned load_persistent_cache
         */
        if (!find_config_tree_bool(cmd, global_use_lvmetad_CFG, NULL) &&
            load_persistent_cache && !cmd->is_long_lived &&
-           !stat(dev_cache, &st) &&
-           (st.st_ctime > config_file_timestamp(cmd->cft)) &&
-           !persistent_filter_load(cmd->filter, NULL))
-               log_verbose("Failed to load existing device cache from %s",
-                           dev_cache);
+           !stat(dev_cache, &st)) {
+               lvm_stat_ctim(&ts, &st);
+               cts = config_file_timestamp(cmd->cft);
+               if (timespeccmp(&ts, &cts, >) &&
+                   !persistent_filter_load(cmd->filter, NULL))
+                       log_verbose("Failed to load existing device cache from %s",
+                                   dev_cache);
+       }
 
        return 1;
 bad:
index 5de6df6d99c83bd6e3cc4be768832c661916b02c..b635654984b4bf22e97f5b3d3b2ff098cebd8854 100644 (file)
@@ -53,7 +53,7 @@ struct config_file {
 
 struct config_source {
        config_source_t type;
-       time_t timestamp;
+       struct timespec timestamp;
        union {
                struct config_file *file;
                struct config_file *profile;
@@ -173,7 +173,7 @@ int config_file_check(struct dm_config_tree *cft, const char **filename, struct
                return 0;
        }
 
-       cs->timestamp = info->st_ctime;
+       lvm_stat_ctim(&cs->timestamp, info);
        cf->exists = 1;
        cf->st_size = info->st_size;
 
@@ -193,6 +193,7 @@ int config_file_changed(struct dm_config_tree *cft)
        struct config_source *cs = dm_config_get_custom(cft);
        struct config_file *cf;
        struct stat info;
+       struct timespec ts;
 
        if (cs->type != CONFIG_FILE) {
                log_error(INTERNAL_ERROR "config_file_changed: expected file config source, "
@@ -226,7 +227,9 @@ int config_file_changed(struct dm_config_tree *cft)
        }
 
        /* Unchanged? */
-       if (cs->timestamp == info.st_ctime && cf->st_size == info.st_size)
+       lvm_stat_ctim(&ts, &info);
+       if ((timespeccmp(&cs->timestamp, &ts, ==)) &&
+           cf->st_size == info.st_size)
                return 0;
 
       reload:
@@ -594,7 +597,7 @@ int config_file_read(struct dm_config_tree *cft)
        return r;
 }
 
-time_t config_file_timestamp(struct dm_config_tree *cft)
+struct timespec config_file_timestamp(struct dm_config_tree *cft)
 {
        struct config_source *cs = dm_config_get_custom(cft);
        return cs->timestamp;
@@ -1473,7 +1476,7 @@ int merge_config_tree(struct cmd_context *cmd, struct dm_config_tree *cft,
        cs = dm_config_get_custom(cft);
        csn = dm_config_get_custom(newdata);
 
-       if (cs && csn && (cs->timestamp < csn->timestamp))
+       if (cs && csn && timespeccmp(&cs->timestamp, &csn->timestamp, <))
                cs->timestamp = csn->timestamp;
 
        return 1;
index 50ea36132617aa8d3db35e1a8b00c9deab17fd16..5fe6a9f16b1cd43b9f6d709989842b01f6d822d0 100644 (file)
@@ -215,7 +215,7 @@ int config_write(struct dm_config_tree *cft, struct config_def_tree_spec *tree_s
 struct dm_config_tree *config_def_create_tree(struct config_def_tree_spec *spec);
 void config_destroy(struct dm_config_tree *cft);
 
-time_t config_file_timestamp(struct dm_config_tree *cft);
+struct timespec config_file_timestamp(struct dm_config_tree *cft);
 int config_file_changed(struct dm_config_tree *cft);
 int config_file_check(struct dm_config_tree *cft, const char **filename, struct stat *info);
 
index b4a7683679b936b8375b37dcef9f96c9feda5f48..8c7b79fd66949d246b7c57c4848732c6994e2f28 100644 (file)
@@ -22,7 +22,7 @@ struct pfilter {
        char *file;
        struct dm_hash_table *devices;
        struct dev_filter *real;
-       time_t ctime;
+       struct timespec ctime;
        struct dev_types *dt;
 };
 
@@ -106,7 +106,7 @@ int persistent_filter_load(struct dev_filter *f, struct dm_config_tree **cft_out
        }
 
        if (!stat(pf->file, &info))
-               pf->ctime = info.st_ctime;
+               lvm_stat_ctim(&pf->ctime, &info);
        else {
                log_very_verbose("%s: stat failed: %s", pf->file,
                                 strerror(errno));
@@ -177,6 +177,7 @@ static int _persistent_filter_dump(struct dev_filter *f, int merge_existing)
        struct pfilter *pf;
        char *tmp_file;
        struct stat info, info2;
+       struct timespec ts;
        struct dm_config_tree *cft = NULL;
        FILE *fp;
        int lockfd;
@@ -227,7 +228,8 @@ static int _persistent_filter_dump(struct dev_filter *f, int merge_existing)
        /*
         * If file contents changed since we loaded it, merge new contents
         */
-       if (merge_existing && info.st_ctime != pf->ctime)
+       lvm_stat_ctim(&ts, &info);
+       if (merge_existing && timespeccmp(&ts, &pf->ctime, !=))
                /* Keep cft open to avoid losing lock */
                persistent_filter_load(f, &cft);
 
@@ -352,7 +354,7 @@ struct dev_filter *persistent_filter_create(struct dev_types *dt,
 
        /* Only merge cache file before dumping it if it changed externally. */
        if (!stat(pf->file, &info))
-               pf->ctime = info.st_ctime;
+               lvm_stat_ctim(&pf->ctime, &info);
 
        f->passes_filter = _lookup_p;
        f->destroy = _persistent_destroy;
This page took 0.057137 seconds and 5 git commands to generate.