~ubuntu-branches/debian/sid/lvm2/sid

« back to all changes in this revision

Viewing changes to lib/metadata/cache_manip.c

  • Committer: Package Import Robot
  • Author(s): Bastian Blank
  • Date: 2014-08-19 15:37:06 UTC
  • mfrom: (1.1.18)
  • Revision ID: package-import@ubuntu.com-20140819153706-i1gaio8lg534dara
Tags: 2.02.109-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
#include "lib.h"
16
16
#include "metadata.h"
17
17
#include "locking.h"
18
 
#include "pv_map.h"
19
18
#include "lvm-string.h"
20
19
#include "toolcontext.h"
21
 
#include "lv_alloc.h"
22
 
#include "pv_alloc.h"
23
20
#include "display.h"
24
21
#include "segtype.h"
25
 
#include "archiver.h"
26
22
#include "activate.h"
27
 
#include "str_list.h"
28
23
#include "defaults.h"
29
 
#include "lvm-exec.h"
30
24
 
31
25
int update_cache_pool_params(struct volume_group *vg, unsigned attr,
32
 
                             int passed_args,
33
 
                             uint32_t data_extents, uint32_t extent_size,
34
 
                             int *chunk_size_calc_method, uint32_t *chunk_size,
35
 
                             thin_discards_t *discards,
36
 
                             uint64_t *pool_metadata_size, int *zero)
 
26
                             int passed_args, uint32_t data_extents,
 
27
                             uint64_t *pool_metadata_size,
 
28
                             int *chunk_size_calc_method, uint32_t *chunk_size)
37
29
{
38
30
        uint64_t min_meta_size;
39
31
 
 
32
        if (!(passed_args & PASS_ARG_CHUNK_SIZE))
 
33
                *chunk_size = DEFAULT_CACHE_POOL_CHUNK_SIZE * 2;
 
34
 
40
35
        if ((*chunk_size < DM_CACHE_MIN_DATA_BLOCK_SIZE) ||
41
36
            (*chunk_size > DM_CACHE_MAX_DATA_BLOCK_SIZE)) {
42
37
                log_error("Chunk size must be in the range %s to %s.",
46
41
        }
47
42
 
48
43
        if (*chunk_size & (DM_CACHE_MIN_DATA_BLOCK_SIZE - 1)) {
49
 
                log_error("Chunk size must be a multiple of %u sectors.",
50
 
                          DM_CACHE_MIN_DATA_BLOCK_SIZE);
 
44
                log_error("Chunk size must be a multiple of %s.",
 
45
                          display_size(vg->cmd, DM_CACHE_MIN_DATA_BLOCK_SIZE));
51
46
                return 0;
52
47
        }
53
48
 
57
52
         * ... plus a good amount of padding (2x) to cover any
58
53
         * policy hint data that may be added in the future.
59
54
         */
60
 
        min_meta_size = 16 * (data_extents * vg->extent_size);
 
55
        min_meta_size = (uint64_t)data_extents * vg->extent_size * 16;
61
56
        min_meta_size /= *chunk_size; /* # of Bytes we need */
62
57
        min_meta_size *= 2;              /* plus some padding */
63
58
        min_meta_size /= 512;            /* in sectors */
66
61
        if (!*pool_metadata_size)
67
62
                *pool_metadata_size = min_meta_size;
68
63
 
69
 
        if (*pool_metadata_size < min_meta_size) {
70
 
                *pool_metadata_size = min_meta_size;
71
 
                log_print("Increasing metadata device size to %"
72
 
                          PRIu64 " sectors", *pool_metadata_size);
73
 
        }
74
64
        if (*pool_metadata_size > (2 * DEFAULT_CACHE_POOL_MAX_METADATA_SIZE)) {
75
65
                *pool_metadata_size = 2 * DEFAULT_CACHE_POOL_MAX_METADATA_SIZE;
76
 
                log_print("Reducing metadata device size to %" PRIu64 " sectors",
77
 
                          *pool_metadata_size);
 
66
                if (passed_args & PASS_ARG_POOL_METADATA_SIZE)
 
67
                        log_warn("WARNING: Maximum supported pool metadata size is %s.",
 
68
                                 display_size(vg->cmd, *pool_metadata_size));
 
69
        } else if (*pool_metadata_size < min_meta_size) {
 
70
                if (passed_args & PASS_ARG_POOL_METADATA_SIZE)
 
71
                        log_warn("WARNING: Minimum supported pool metadata size is %s "
 
72
                                 "(needs extra %s).",
 
73
                                 display_size(vg->cmd, min_meta_size),
 
74
                                 display_size(vg->cmd, min_meta_size - *pool_metadata_size));
 
75
                *pool_metadata_size = min_meta_size;
78
76
        }
79
77
 
80
78
        return 1;
302
300
 
303
301
        return 1;
304
302
}
 
303
 
 
304
int get_cache_mode(const char *str, uint32_t *flags)
 
305
{
 
306
        if (!strcmp(str, "writethrough"))
 
307
                *flags |= DM_CACHE_FEATURE_WRITETHROUGH;
 
308
        else if (!strcmp(str, "writeback"))
 
309
                *flags |= DM_CACHE_FEATURE_WRITEBACK;
 
310
        else {
 
311
                log_error("Cache pool cachemode \"%s\" is unknown.", str);
 
312
                return 0;
 
313
        }
 
314
 
 
315
        return 1;
 
316
}