]> sourceware.org Git - lvm2.git/commitdiff
cache: include cache mode in vg metadata and display
authorDavid Teigland <teigland@redhat.com>
Wed, 1 Oct 2014 21:06:01 +0000 (16:06 -0500)
committerDavid Teigland <teigland@redhat.com>
Thu, 2 Oct 2014 16:17:41 +0000 (11:17 -0500)
The cache mode of a new cache pool is always explicitly
included in the vg metadata.  If a cache mode is not
specified on the command line, the cache mode is taken
from lvm.conf allocation/cache_pool_cachemode, which
defaults to "writethrough".

The cache mode can be displayed with lvs -o+cachemode.

13 files changed:
conf/example.conf.in
lib/config/config_settings.h
lib/config/defaults.h
lib/metadata/cache_manip.c
lib/metadata/lv.c
lib/metadata/lv.h
lib/metadata/metadata-exported.h
lib/report/columns.h
lib/report/properties.c
lib/report/report.c
man/lvm.conf.5.in
tools/lvconvert.c
tools/lvcreate.c

index dd1d066eb7517cb38edd0f9dbefed9840094c1ed..d1da23f81fcd7a9487293f5d472f77fbf34082c4 100644 (file)
@@ -335,6 +335,15 @@ allocation {
     # range from 32(kiB) to 1048576 in multiples of 32.
     # cache_pool_chunk_size = 64
 
+    # Specify the default cache mode used for new cache pools.
+    # Possible options are:
+    # "writethrough"    - Data blocks are immediately written from
+    #                     the cache to disk.
+    # "writeback"       - Data blocks are written from the cache
+    #                     back to disk after some delay to improve
+    #                     performance.
+    # cache_pool_cachemode = "writethrough"
+
     # Set to 1 to guarantee that thin pool metadata will always
     # be placed on different PVs from the pool data.
     thin_pool_metadata_require_separate_pvs = 0
index 7724c5725437c2accd39c30291d2fdb9aae2c37a..a6c1d1b049df4043ff34f523b2622fd96a0760cd 100644 (file)
@@ -120,6 +120,7 @@ cfg(allocation_use_blkid_wiping_CFG, "use_blkid_wiping", allocation_CFG_SECTION,
 cfg(allocation_wipe_signatures_when_zeroing_new_lvs_CFG, "wipe_signatures_when_zeroing_new_lvs", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, 1, vsn(2, 2, 105), NULL)
 cfg(allocation_mirror_logs_require_separate_pvs_CFG, "mirror_logs_require_separate_pvs", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_MIRROR_LOGS_REQUIRE_SEPARATE_PVS, vsn(2, 2, 85), NULL)
 cfg(allocation_cache_pool_metadata_require_separate_pvs_CFG, "cache_pool_metadata_require_separate_pvs", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_CACHE_POOL_METADATA_REQUIRE_SEPARATE_PVS, vsn(2, 2, 106), NULL)
+cfg(allocation_cache_pool_cachemode_CFG, "cache_pool_cachemode", allocation_CFG_SECTION, 0, CFG_TYPE_STRING, DEFAULT_CACHE_POOL_CACHEMODE, vsn(2, 2, 113), NULL)
 cfg_runtime(allocation_cache_pool_chunk_size_CFG, "cache_pool_chunk_size", allocation_CFG_SECTION, CFG_DEFAULT_UNDEFINED, CFG_TYPE_INT, vsn(2, 2, 106), NULL)
 cfg(allocation_thin_pool_metadata_require_separate_pvs_CFG, "thin_pool_metadata_require_separate_pvs", allocation_CFG_SECTION, 0, CFG_TYPE_BOOL, DEFAULT_THIN_POOL_METADATA_REQUIRE_SEPARATE_PVS, vsn(2, 2, 89), NULL)
 cfg(allocation_thin_pool_zero_CFG, "thin_pool_zero", allocation_CFG_SECTION, CFG_PROFILABLE | CFG_PROFILABLE_METADATA, CFG_TYPE_BOOL, DEFAULT_THIN_POOL_ZERO, vsn(2, 2, 99), NULL)
index 05187b08c1201c651ee24d9de23aa9605b5c5871..2cb1e5aa9071508ade5ead7f9fe6adc1a2286ad8 100644 (file)
@@ -96,6 +96,7 @@
 #define DEFAULT_CACHE_POOL_CHUNK_SIZE 64 /* KB */
 #define DEFAULT_CACHE_POOL_MIN_METADATA_SIZE 2048  /* KB */
 #define DEFAULT_CACHE_POOL_MAX_METADATA_SIZE (16 * 1024 * 1024)  /* KB */
+#define DEFAULT_CACHE_POOL_CACHEMODE "writethrough"
 
 #define DEFAULT_UMASK 0077
 
index 7f5ea65c35fec7352cf7c6a59e93eb8a58bdf481..a44bba89723af92718e2abad7b2c36e7be4008be 100644 (file)
 #include "activate.h"
 #include "defaults.h"
 
+const char *get_cachepool_cachemode_name(const struct lv_segment *seg)
+{
+       if (seg->feature_flags & DM_CACHE_FEATURE_WRITEBACK)
+               return "writeback";
+
+       if (seg->feature_flags & DM_CACHE_FEATURE_WRITETHROUGH)
+               return "writethrough";
+
+       return "unknown";
+}
+
 int update_cache_pool_params(struct volume_group *vg, unsigned attr,
                             int passed_args, uint32_t data_extents,
                             uint64_t *pool_metadata_size,
index d29e787aae0a63ebd3428372272669cd37e7bb51..23f0991dcb6717534eaba33b84c8d689cb9938e5 100644 (file)
@@ -128,6 +128,11 @@ char *lvseg_discards_dup(struct dm_pool *mem, const struct lv_segment *seg)
        return  dm_pool_strdup(mem, get_pool_discards_name(seg->discards));
 }
 
+char *lvseg_cachemode_dup(struct dm_pool *mem, const struct lv_segment *seg)
+{
+       return dm_pool_strdup(mem, get_cachepool_cachemode_name(seg));
+}
+
 #ifdef DMEVENTD
 #  include "libdevmapper-event.h"
 #endif
index d43bc01adea865ee91f28abed9613fbb94dc60ea..bcd702880ac641d498fff45330655b659b42a80e 100644 (file)
@@ -82,6 +82,7 @@ uint64_t lvseg_size(const struct lv_segment *seg);
 uint64_t lvseg_chunksize(const struct lv_segment *seg);
 char *lvseg_segtype_dup(struct dm_pool *mem, const struct lv_segment *seg);
 char *lvseg_discards_dup(struct dm_pool *mem, const struct lv_segment *seg);
+char *lvseg_cachemode_dup(struct dm_pool *mem, const struct lv_segment *seg);
 char *lvseg_monitor_dup(struct dm_pool *mem, const struct lv_segment *seg);
 char *lvseg_tags_dup(const struct lv_segment *seg);
 char *lvseg_devices(struct dm_pool *mem, const struct lv_segment *seg);
index 5787f5a1368de77cc8d4936ec42167252ed5ba04..b392bde990acc537935405c636f34f5db93ab5ee 100644 (file)
@@ -1069,6 +1069,7 @@ int partial_raid_lv_supports_degraded_activation(const struct logical_volume *lv
 /* --  metadata/raid_manip.c */
 
 /* ++  metadata/cache_manip.c */
+const char *get_cachepool_cachemode_name(const struct lv_segment *seg);
 int update_cache_pool_params(struct volume_group *vg, unsigned attr,
                             int passed_args, uint32_t data_extents,
                             uint64_t *pool_metadata_size,
index 796ac4ec16328a32454bd1bf7cbf2d7789bb30f9..a2f34f9281229c06a062094cf8cf3c9381cc04d5 100644 (file)
@@ -158,6 +158,7 @@ FIELD(SEGS, seg, SIZ, "Chunk", list, 5, chunksize, chunksize, "For snapshots, th
 FIELD(SEGS, seg, SIZ, "Chunk", list, 5, chunksize, chunk_size, "For snapshots, the unit of data used when tracking changes.", 0)
 FIELD(SEGS, seg, NUM, "#Thins", list, 4, thincount, thin_count, "For thin pools, the number of thin volumes in this pool.", 0)
 FIELD(SEGS, seg, STR, "Discards", list, 8, discards, discards, "For thin pools, how discards are handled.", 0)
+FIELD(SEGS, seg, STR, "Cachemode", list, 9, cachemode, cachemode, "For cache pools, how writes are cached.", 0)
 FIELD(SEGS, seg, BIN, "Zero", list, 4, thinzero, zero, "For thin pools, if zeroing is enabled.", 0)
 FIELD(SEGS, seg, NUM, "TransId", list, 4, transactionid, transaction_id, "For thin pools, the transaction id.", 0)
 FIELD(SEGS, seg, NUM, "ThId", list, 4, thinid, thin_id, "For thin volume, the thin device id.", 0)
index e0092dbfc96a6f1f1a15add6535308ec1847be0e..8f4f472507a0c411651a2459d423c37dfb854f46 100644 (file)
@@ -380,6 +380,8 @@ GET_LVSEG_NUM_PROPERTY_FN(thin_id, lvseg->device_id)
 #define _thin_id_set prop_not_implemented_set
 GET_LVSEG_STR_PROPERTY_FN(discards, lvseg_discards_dup(lvseg->lv->vg->vgmem, lvseg))
 #define _discards_set prop_not_implemented_set
+GET_LVSEG_STR_PROPERTY_FN(cachemode, lvseg_cachemode_dup(lvseg->lv->vg->vgmem, lvseg))
+#define _cachemode_set prop_not_implemented_set
 GET_LVSEG_NUM_PROPERTY_FN(seg_start, (SECTOR_SIZE * lvseg_start(lvseg)))
 #define _seg_start_set prop_not_implemented_set
 GET_LVSEG_NUM_PROPERTY_FN(seg_start_pe, lvseg->le)
index c34aa5e6f030a86854f0c8f9eee59e76b45ca276..69f75ed91e06d98938886552a0e61fee5bd07d40 100644 (file)
@@ -773,6 +773,24 @@ static int _discards_disp(struct dm_report *rh, struct dm_pool *mem,
        return _field_set_value(field, "", NULL);
 }
 
+static int _cachemode_disp(struct dm_report *rh, struct dm_pool *mem,
+                          struct dm_report_field *field,
+                          const void *data, void *private)
+{
+       const struct lv_segment *seg = (const struct lv_segment *) data;
+       const char *cachemode_str;
+
+       if (seg_is_cache(seg))
+               seg = first_seg(seg->pool_lv);
+
+       if (seg_is_cache_pool(seg)) {
+               cachemode_str = get_cachepool_cachemode_name(seg);
+               return dm_report_field_string(rh, field, &cachemode_str);
+       }
+
+       return _field_set_value(field, "", NULL);
+}
+
 static int _originsize_disp(struct dm_report *rh, struct dm_pool *mem,
                            struct dm_report_field *field,
                            const void *data, void *private)
index c4345270a01ef2e19b4c2d40808b92813f048023..5bc20815680b37a3b0661f333350a2ed9336fe09 100644 (file)
@@ -299,6 +299,15 @@ they are situated and these two PV tags are selected for use with this
 allocation policy:
 .IP
 cling_tag_list = [ "@site1", "@site2" ]
+.IP
+\fBcache_pool_cachemode\fP \(em Cache mode for new cache pools.
+.IP
+This is the default cache mode a new cache pool will be given.
+Valid cache modes are:
+\fBwritethrough\fP - Data blocks are immediately written from the
+cache to disk.
+\fBwriteback\fP - Data blocks are written from the cache
+back to disk after some delay to improve performance.
 .TP
 \fBlog\fP \(em Default log settings
 .IP
index c05ea1b822fcca754507555a07ff527a9d14c5b3..09257e333832ba3874cc2171ea1ca35be1676f8a 100644 (file)
@@ -204,7 +204,6 @@ static int _mirror_or_raid_type_requested(struct cmd_context *cmd, const char *t
 static int _read_pool_params(struct lvconvert_params *lp, struct cmd_context *cmd,
                             const char *type_str, int *pargc, char ***pargv)
 {
-       const char *tmp_str;
        int cachepool = 0;
        int thinpool = 0;
 
@@ -234,8 +233,11 @@ static int _read_pool_params(struct lvconvert_params *lp, struct cmd_context *cm
                thinpool = 1;
 
        if (cachepool) {
-               if ((tmp_str = arg_str_value(cmd, cachemode_ARG, NULL)) &&
-                   !get_cache_mode(tmp_str, &lp->feature_flags))
+               const char *cachemode = arg_str_value(cmd, cachemode_ARG, NULL);
+               if (!cachemode)
+                       cachemode = find_config_tree_str(cmd, allocation_cache_pool_cachemode_CFG, NULL);
+
+               if (!get_cache_mode(cachemode, &lp->feature_flags))
                        return_0;
        } else {
                if (arg_from_list_is_set(cmd, "is valid only with cache pools",
index 17fcd46d618dd90fb5263245c49409ee7ef25b0e..bb3892db1792250f7a6de29c944495369db96b0e 100644 (file)
@@ -693,13 +693,16 @@ static int _read_raid_params(struct lvcreate_params *lp,
 static int _read_cache_pool_params(struct lvcreate_params *lp,
                                  struct cmd_context *cmd)
 {
-       const char *str_arg;
+       const char *cachemode;
 
        if (!segtype_is_cache_pool(lp->segtype))
                return 1;
 
-       if ((str_arg = arg_str_value(cmd, cachemode_ARG, NULL)) &&
-           !get_cache_mode(str_arg, &lp->feature_flags))
+       cachemode = arg_str_value(cmd, cachemode_ARG, NULL);
+       if (!cachemode)
+               cachemode = find_config_tree_str(cmd, allocation_cache_pool_cachemode_CFG, NULL);
+
+       if (!get_cache_mode(cachemode, &lp->feature_flags))
                return_0;
 
        return 1;
This page took 0.051115 seconds and 5 git commands to generate.