summaryrefslogtreecommitdiffstats
path: root/lib/format_pool/disk_rep.h
blob: fff734367b02aa989fcc83d025402811e254980c (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
 * Copyright (C) 1997-2004 Sistina Software, Inc. All rights reserved.  
 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
 *
 * 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 DISK_REP_FORMAT_POOL_H
#define DISK_REP_FORMAT_POOL_H

#include "label.h"
#include "metadata.h"

#define MINOR_OFFSET 65536

/* From NSP.cf */
#define NSPMajorVersion	4
#define NSPMinorVersion	1
#define NSPUpdateLevel	3

/* From pool_std.h */
#define POOL_NAME_SIZE          (256)
#define POOL_MAGIC 		0x011670
#define POOL_MAJOR              (121)
#define POOL_MAX_DEVICES 	128

/* When checking for version matching, the first two numbers **
** are important for metadata formats, a.k.a pool labels.   **
** All the numbers are important when checking if the user  **
** space tools match up with the kernel module............. */
#define POOL_VERSION		(NSPMajorVersion << 16 | \
				 NSPMinorVersion <<  8 | \
				 NSPUpdateLevel)

/* Pool label is at the head of every pool disk partition */
#define SIZEOF_POOL_LABEL       (8192)

/* in sectors */
#define POOL_PE_SIZE     (SIZEOF_POOL_LABEL >> SECTOR_SHIFT)
#define POOL_PE_START    (SIZEOF_POOL_LABEL >> SECTOR_SHIFT)

/* Helper fxns */
#define get_pool_vg_uuid(id, pd) do { get_pool_uuid((char *)(id), \
                                                    (pd)->pl_pool_id, 0, 0); \
                                    } while(0)
#define get_pool_pv_uuid(id, pd) do { get_pool_uuid((char *)(id), \
                                                    (pd)->pl_pool_id, \
                                                    (pd)->pl_sp_id, \
                                                    (pd)->pl_sp_devid); \
                                    } while(0)
#define get_pool_lv_uuid(id, pd) do { get_pool_uuid((char *)&(id)[0], \
                                                    (pd)->pl_pool_id, 0, 0); \
                                      get_pool_uuid((char*)&(id)[1], \
                                                    (pd)->pl_pool_id, 0, 0); \
                                    } while(0)

struct pool_disk;
struct pool_list;
struct user_subpool;
struct user_device;

struct pool_disk {
	uint64_t pl_magic;	/* Pool magic number */
	uint64_t pl_pool_id;	/* Unique pool identifier */
	char pl_pool_name[POOL_NAME_SIZE];	/* Name of pool */
	uint32_t pl_version;	/* Pool version */
	uint32_t pl_subpools;	/* Number of subpools in this pool */
	uint32_t pl_sp_id;	/* Subpool number within pool */
	uint32_t pl_sp_devs;	/* Number of data partitions in this subpool */
	uint32_t pl_sp_devid;	/* Partition number within subpool */
	uint32_t pl_sp_type;	/* Partition type */
	uint64_t pl_blocks;	/* Number of blocks in this partition */
	uint32_t pl_striping;	/* Striping size within subpool */
	/*
	 * If the number of DMEP devices is zero, then the next field **
	 * ** (pl_sp_dmepid) becomes the subpool ID for redirection.  In **
	 * ** other words, if this subpool does not have the capability  **
	 * ** to do DMEP, then it must specify which subpool will do it  **
	 * ** in it's place
	 */

	/*
	 * While the next 3 field are no longer used, they must stay to keep **
	 * ** backward compatibility...........................................
	 */
	uint32_t pl_sp_dmepdevs;/* Number of dmep devices in this subpool */
	uint32_t pl_sp_dmepid;	/* Dmep device number within subpool */
	uint32_t pl_sp_weight;	/* if dmep dev, pref to using it */

	uint32_t pl_minor;	/* the pool minor number */
	uint32_t pl_padding;	/* reminder - think about alignment */

	/*
	 * Even though we're zeroing out 8k at the front of the disk before
	 * writing the label, putting this in
	 */
	char pl_reserve[184];	/* bump the structure size out to 512 bytes */
};

struct pool_list {
	struct dm_list list;
	struct pool_disk pd;
	struct physical_volume *pv;
	struct id pv_uuid;
	struct device *dev;
};

struct user_subpool {
	uint32_t initialized;
	uint32_t id;
	uint32_t striping;
	uint32_t num_devs;
	uint32_t type;
	uint32_t dummy;
	struct user_device *devs;
};

struct user_device {
	uint32_t initialized;
	uint32_t sp_id;
	uint32_t devid;
	uint32_t dummy;
	uint64_t blocks;
	struct physical_volume *pv;
};

int read_pool_label(struct pool_list *pl, struct labeller *l,
		    struct device *dev, char *buf, struct label **label);
void pool_label_out(struct pool_disk *pl, void *buf);
void pool_label_in(struct pool_disk *pl, void *buf);
void get_pool_uuid(char *uuid, uint64_t poolid, uint32_t spid, uint32_t devid);
int import_pool_vg(struct volume_group *vg, struct dm_pool *mem, struct dm_list *pls);
int import_pool_lvs(struct volume_group *vg, struct dm_pool *mem,
		    struct dm_list *pls);
int import_pool_pvs(const struct format_type *fmt, struct volume_group *vg,
		    struct dm_pool *mem, struct dm_list *pls);
int import_pool_pv(const struct format_type *fmt, struct dm_pool *mem,
		   struct volume_group *vg, struct physical_volume *pv,
		   struct pool_list *pl);
int import_pool_segments(struct dm_list *lvs, struct dm_pool *mem,
			 struct user_subpool *usp, int sp_count);
int read_pool_pds(const struct format_type *fmt, const char *vgname,
		  struct dm_pool *mem, struct dm_list *head);
struct pool_list *read_pool_disk(const struct format_type *fmt,
				 struct device *dev, struct dm_pool *mem,
				 const char *vg_name);

#endif				/* DISK_REP_POOL_FORMAT_H */