summaryrefslogtreecommitdiffstats
path: root/lib/cache/lvmetad.h
blob: 713c5a308b8f8bd7dda5c349a695c609a6c7af14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
 * Copyright (C) 2012 Red Hat, Inc.
 *
 * This file is part of LVM2.
 *
 * This copyrighted material is made available to anyone wishing to use,
 * modify, copy, or redistribute it subject to the terms and conditions
 * of the GNU Lesser General Public License v.2.1.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef _LVM_METAD_H
#define _LVM_METAD_H

struct volume_group;
struct cmd_context;
struct dm_config_tree;

typedef int (*activation_handler) (struct volume_group *vg, int partial, int activate);

#ifdef LVMETAD_SUPPORT
/*
 * Initialise the communication with lvmetad. Normally called by
 * lvmcache_init. Sets up a global handle for our process.
 */
void lvmetad_init(void);

/*
 * Override the use of lvmetad for retrieving scan results and metadata.
 */
void lvmetad_set_active(int);

/*
 * Check whether lvmetad is active (where active means both that it is running
 * and that we have a working connection with it).
 */
int lvmetad_active(void);

/*
 * Send a new version of VG metadata to lvmetad. This is normally called after
 * vg_write but before vg_commit. After vg_commit, lvmetad_vg_commit is called
 * to seal the transaction. The result of lvmetad_vg_update is that the new
 * metadata is stored tentatively in lvmetad, but it is not used until
 * lvmetad_vg_commit. The request is validated immediately and lvmetad_vg_commit
 * only constitutes a pointer update.
 */
int lvmetad_vg_update(struct volume_group *vg);

/*
 * Inform lvmetad that a VG has been removed. This is not entirely safe, but is
 * only needed during vgremove, which does not wipe PV labels and therefore
 * cannot mark the PVs as gone.
 */
int lvmetad_vg_remove(struct volume_group *vg);

/*
 * Notify lvmetad that a PV has been found. It is not an error if the PV is
 * already marked as present in lvmetad. If a non-NULL vg pointer is supplied,
 * it is taken to represent the metadata read from the MDA(s) present on that
 * PV. It *is* an error if: the VG is already known to lvmetad, the sequence
 * number on the cached and on the discovered PV match but the metadata content
 * does not.
 */
int lvmetad_pv_found(struct id pvid, struct device *device,
		     const struct format_type *fmt, uint64_t label_sector,
		     struct volume_group *vg, activation_handler handler);

/*
 * Inform the daemon that the device no longer exists.
 */
int lvmetad_pv_gone(dev_t devno, const char *pv_name, activation_handler handler);
int lvmetad_pv_gone_by_dev(struct device *dev, activation_handler handler);

/*
 * Request a list of all PVs available to lvmetad. If requested, this will also
 * read labels off all the PVs to populate lvmcache.
 */
int lvmetad_pv_list_to_lvmcache(struct cmd_context *cmd);

/*
 * Lookup an individual PV.
 * If found is not NULL, it is set according to whether or not the PV is found,
 * otherwise if the PV is not found an error is returned.
 */
int lvmetad_pv_lookup(struct cmd_context *cmd, struct id pvid, int *found);
int lvmetad_pv_lookup_by_dev(struct cmd_context *cmd, struct device *dev, int *found);

/*
 * Request a list of all VGs available to lvmetad and use it to fill in
 * lvmcache..
 */
int lvmetad_vg_list_to_lvmcache(struct cmd_context *cmd);

/*
 * Find a VG by its ID or its name in the lvmetad cache. Gives NULL if the VG is
 * not found.
 */
struct volume_group *lvmetad_vg_lookup(struct cmd_context *cmd,
				       const char *vgname, const char *vgid);

/*
 * Scan a single device and update lvmetad with the result(s).
 */
int pvscan_lvmetad_single(struct cmd_context *cmd, struct device *dev,
			  activation_handler handler);

#  else		/* LVMETAD_SUPPORT */

#    define lvmetad_init()	do { } while (0)
#    define lvmetad_set_active(a)	do { } while (0)
#    define lvmetad_active()	(0)
#    define lvmetad_vg_update(vg)	(1)
#    define lvmetad_vg_remove(vg)	(1)
#    define lvmetad_pv_found(pvid, device, fmt, label_sector, vg, handler)	(1)
#    define lvmetad_pv_gone(devno, pv_name, handler)	(1)
#    define lvmetad_pv_gone_by_dev(dev, handler)	(1)
#    define lvmetad_pv_list_to_lvmcache(cmd)	(1)
#    define lvmetad_pv_lookup(cmd, pvid, found)	(0)
#    define lvmetad_pv_lookup_by_dev(cmd, dev, found)	(0)
#    define lvmetad_vg_list_to_lvmcache(cmd)	(1)
#    define lvmetad_vg_lookup(cmd, vgname, vgid)	(NULL)
#    define pvscan_lvmetad_single(cmd, dev, handler)	(0)

#  endif	/* LVMETAD_SUPPORT */

#endif