]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (C) 2002-2004 Sistina Software, Inc. All rights reserved. | |
3 | * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved. | |
4 | * | |
5 | * This file is part of LVM2. | |
6 | * | |
7 | * This copyrighted material is made available to anyone wishing to use, | |
8 | * modify, copy, or redistribute it subject to the terms and conditions | |
9 | * of the GNU Lesser General Public License v.2.1. | |
10 | * | |
11 | * You should have received a copy of the GNU Lesser General Public License | |
12 | * along with this program; if not, write to the Free Software Foundation, | |
13 | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
14 | */ | |
15 | ||
16 | #ifndef _LVM_LABEL_H | |
17 | #define _LVM_LABEL_H | |
18 | ||
19 | #include "lib/uuid/uuid.h" | |
20 | #include "lib/device/device.h" | |
21 | #include "lib/device/bcache.h" | |
22 | ||
23 | #define LABEL_ID "LABELONE" | |
24 | #define LABEL_SIZE SECTOR_SIZE /* Think very carefully before changing this */ | |
25 | #define LABEL_SCAN_SECTORS 4L | |
26 | #define LABEL_SCAN_SIZE (LABEL_SCAN_SECTORS << SECTOR_SHIFT) | |
27 | ||
28 | struct labeller; | |
29 | struct dev_filter; | |
30 | struct cmd_context; | |
31 | struct logical_volume; | |
32 | ||
33 | /* On disk - 32 bytes */ | |
34 | struct label_header { | |
35 | int8_t id[8]; /* LABELONE */ | |
36 | uint64_t sector_xl; /* Sector number of this label */ | |
37 | uint32_t crc_xl; /* From next field to end of sector */ | |
38 | uint32_t offset_xl; /* Offset from start of struct to contents */ | |
39 | int8_t type[8]; /* LVM2 001 */ | |
40 | } __attribute__ ((packed)); | |
41 | ||
42 | /* In core */ | |
43 | struct label { | |
44 | char type[8]; | |
45 | uint64_t sector; | |
46 | struct labeller *labeller; | |
47 | struct device *dev; | |
48 | void *info; | |
49 | }; | |
50 | ||
51 | struct labeller; | |
52 | ||
53 | struct label_ops { | |
54 | /* | |
55 | * Is the device labelled with this format ? | |
56 | */ | |
57 | int (*can_handle) (struct labeller * l, void *buf, uint64_t sector); | |
58 | ||
59 | /* | |
60 | * Write a label to a volume. | |
61 | */ | |
62 | int (*write) (struct label * label, void *buf); | |
63 | ||
64 | /* | |
65 | * Read a label from a volume. | |
66 | */ | |
67 | int (*read) (struct cmd_context *cmd, struct labeller * l, struct device * dev, | |
68 | void *label_buf, uint64_t label_sector, int *is_duplicate); | |
69 | ||
70 | /* | |
71 | * Populate label_type etc. | |
72 | */ | |
73 | int (*initialise_label) (struct labeller * l, struct label * label); | |
74 | ||
75 | /* | |
76 | * Destroy a previously read label. | |
77 | */ | |
78 | void (*destroy_label) (struct labeller * l, struct label * label); | |
79 | ||
80 | /* | |
81 | * Destructor. | |
82 | */ | |
83 | void (*destroy) (struct labeller * l); | |
84 | }; | |
85 | ||
86 | struct labeller { | |
87 | const struct label_ops *ops; | |
88 | const struct format_type *fmt; | |
89 | }; | |
90 | ||
91 | int label_init(void); | |
92 | void label_exit(void); | |
93 | ||
94 | int label_register_handler(struct labeller *handler); | |
95 | ||
96 | struct labeller *label_get_handler(const char *name); | |
97 | ||
98 | int label_remove(struct device *dev); | |
99 | int label_write(struct device *dev, struct label *label); | |
100 | struct label *label_create(struct labeller *labeller); | |
101 | void label_destroy(struct label *label); | |
102 | ||
103 | int label_scan(struct cmd_context *cmd); | |
104 | int label_scan_devs(struct cmd_context *cmd, struct dev_filter *f, struct dm_list *devs); | |
105 | int label_scan_devs_cached(struct cmd_context *cmd, struct dev_filter *f, struct dm_list *devs); | |
106 | int label_scan_devs_rw(struct cmd_context *cmd, struct dev_filter *f, struct dm_list *devs); | |
107 | int label_scan_devs_excl(struct cmd_context *cmd, struct dev_filter *f, struct dm_list *devs); | |
108 | int label_scan_dev(struct cmd_context *cmd, struct device *dev); | |
109 | void label_scan_invalidate(struct device *dev); | |
110 | void label_scan_invalidate_lv(struct cmd_context *cmd, struct logical_volume *lv); | |
111 | void label_scan_invalidate_lvs(struct cmd_context *cmd, struct dm_list *lvs); | |
112 | void label_scan_drop(struct cmd_context *cmd); | |
113 | void label_scan_destroy(struct cmd_context *cmd); | |
114 | int label_scan_setup_bcache(void); | |
115 | int label_scan_open(struct device *dev); | |
116 | int label_scan_open_excl(struct device *dev); | |
117 | int label_scan_open_rw(struct device *dev); | |
118 | int label_scan_reopen_rw(struct device *dev); | |
119 | int label_read_pvid(struct device *dev, int *has_pvid); | |
120 | int label_scan_vg_online(struct cmd_context *cmd, const char *vgname, | |
121 | int *found_none, int *found_all, int *found_incomplete); | |
122 | ||
123 | ||
124 | int label_scan_for_pvid(struct cmd_context *cmd, char *pvid, struct device **dev_out); | |
125 | ||
126 | /* | |
127 | * Wrappers around bcache equivalents. | |
128 | * (these make it easier to disable bcache and revert to direct rw if needed) | |
129 | */ | |
130 | bool dev_read_bytes(struct device *dev, uint64_t start, size_t len, void *data); | |
131 | bool dev_write_bytes(struct device *dev, uint64_t start, size_t len, void *data); | |
132 | bool dev_write_zeros(struct device *dev, uint64_t start, size_t len); | |
133 | bool dev_set_bytes(struct device *dev, uint64_t start, size_t len, uint8_t val); | |
134 | bool dev_invalidate_bytes(struct device *dev, uint64_t start, size_t len); | |
135 | void dev_invalidate(struct device *dev); | |
136 | void dev_set_last_byte(struct device *dev, uint64_t offset); | |
137 | void dev_unset_last_byte(struct device *dev); | |
138 | ||
139 | void prepare_open_file_limit(struct cmd_context *cmd, unsigned int num_devs); | |
140 | ||
141 | #endif |