]> sourceware.org Git - lvm2.git/blame_incremental - lib/label/label.h
device_id: fix segfault if devices file has PVID=.
[lvm2.git] / lib / label / label.h
... / ...
CommitLineData
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
28struct labeller;
29struct dev_filter;
30struct cmd_context;
31struct logical_volume;
32
33/* On disk - 32 bytes */
34struct 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 */
43struct label {
44 char type[8];
45 uint64_t sector;
46 struct labeller *labeller;
47 struct device *dev;
48 void *info;
49};
50
51struct labeller;
52
53struct 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
86struct labeller {
87 const struct label_ops *ops;
88 const struct format_type *fmt;
89};
90
91int label_init(void);
92void label_exit(void);
93
94int label_register_handler(struct labeller *handler);
95
96struct labeller *label_get_handler(const char *name);
97
98int label_remove(struct device *dev);
99int label_write(struct device *dev, struct label *label);
100struct label *label_create(struct labeller *labeller);
101void label_destroy(struct label *label);
102
103int label_scan(struct cmd_context *cmd);
104int label_scan_devs(struct cmd_context *cmd, struct dev_filter *f, struct dm_list *devs);
105int label_scan_devs_cached(struct cmd_context *cmd, struct dev_filter *f, struct dm_list *devs);
106int label_scan_devs_rw(struct cmd_context *cmd, struct dev_filter *f, struct dm_list *devs);
107int label_scan_devs_excl(struct cmd_context *cmd, struct dev_filter *f, struct dm_list *devs);
108int label_scan_dev(struct cmd_context *cmd, struct device *dev);
109void label_scan_invalidate(struct device *dev);
110void label_scan_invalidate_lv(struct cmd_context *cmd, struct logical_volume *lv);
111void label_scan_invalidate_lvs(struct cmd_context *cmd, struct dm_list *lvs);
112void label_scan_drop(struct cmd_context *cmd);
113void label_scan_destroy(struct cmd_context *cmd);
114int label_scan_setup_bcache(void);
115int label_scan_open(struct device *dev);
116int label_scan_open_excl(struct device *dev);
117int label_scan_open_rw(struct device *dev);
118int label_scan_reopen_rw(struct device *dev);
119int label_read_pvid(struct device *dev, int *has_pvid);
120int label_scan_vg_online(struct cmd_context *cmd, const char *vgname,
121 int *found_none, int *found_all, int *found_incomplete);
122
123
124int 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 */
130bool dev_read_bytes(struct device *dev, uint64_t start, size_t len, void *data);
131bool dev_write_bytes(struct device *dev, uint64_t start, size_t len, void *data);
132bool dev_write_zeros(struct device *dev, uint64_t start, size_t len);
133bool dev_set_bytes(struct device *dev, uint64_t start, size_t len, uint8_t val);
134bool dev_invalidate_bytes(struct device *dev, uint64_t start, size_t len);
135void dev_invalidate(struct device *dev);
136void dev_set_last_byte(struct device *dev, uint64_t offset);
137void dev_unset_last_byte(struct device *dev);
138
139void prepare_open_file_limit(struct cmd_context *cmd, unsigned int num_devs);
140
141#endif
This page took 0.03042 seconds and 6 git commands to generate.