1/*	$NetBSD: disk_rep.h,v 1.1.1.1 2008/12/22 00:17:50 haad Exp $	*/
2
3/*
4 * Copyright (C) 1997-2004 Sistina Software, Inc. All rights reserved.
5 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
6 *
7 * This file is part of LVM2.
8 *
9 * This copyrighted material is made available to anyone wishing to use,
10 * modify, copy, or redistribute it subject to the terms and conditions
11 * of the GNU Lesser General Public License v.2.1.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16 */
17
18#ifndef DISK_REP_FORMAT_POOL_H
19#define DISK_REP_FORMAT_POOL_H
20
21#include "label.h"
22#include "metadata.h"
23
24#define MINOR_OFFSET 65536
25
26/* From NSP.cf */
27#define NSPMajorVersion	4
28#define NSPMinorVersion	1
29#define NSPUpdateLevel	3
30
31/* From pool_std.h */
32#define POOL_NAME_SIZE          (256)
33#define POOL_MAGIC 		0x011670
34#define POOL_MAJOR              (121)
35#define POOL_MAX_DEVICES 	128
36
37/* When checking for version matching, the first two numbers **
38** are important for metadata formats, a.k.a pool labels.   **
39** All the numbers are important when checking if the user  **
40** space tools match up with the kernel module............. */
41#define POOL_VERSION		(NSPMajorVersion << 16 | \
42				 NSPMinorVersion <<  8 | \
43				 NSPUpdateLevel)
44
45/* Pool label is at the head of every pool disk partition */
46#define SIZEOF_POOL_LABEL       (8192)
47
48/* in sectors */
49#define POOL_PE_SIZE     (SIZEOF_POOL_LABEL >> SECTOR_SHIFT)
50#define POOL_PE_START    (SIZEOF_POOL_LABEL >> SECTOR_SHIFT)
51
52/* Helper fxns */
53#define get_pool_vg_uuid(id, pd) do { get_pool_uuid((char *)(id), \
54                                                    (pd)->pl_pool_id, 0, 0); \
55                                    } while(0)
56#define get_pool_pv_uuid(id, pd) do { get_pool_uuid((char *)(id), \
57                                                    (pd)->pl_pool_id, \
58                                                    (pd)->pl_sp_id, \
59                                                    (pd)->pl_sp_devid); \
60                                    } while(0)
61#define get_pool_lv_uuid(id, pd) do { get_pool_uuid((char *)&(id)[0], \
62                                                    (pd)->pl_pool_id, 0, 0); \
63                                      get_pool_uuid((char*)&(id)[1], \
64                                                    (pd)->pl_pool_id, 0, 0); \
65                                    } while(0)
66
67struct pool_disk;
68struct pool_list;
69struct user_subpool;
70struct user_device;
71
72struct pool_disk {
73	uint64_t pl_magic;	/* Pool magic number */
74	uint64_t pl_pool_id;	/* Unique pool identifier */
75	char pl_pool_name[POOL_NAME_SIZE];	/* Name of pool */
76	uint32_t pl_version;	/* Pool version */
77	uint32_t pl_subpools;	/* Number of subpools in this pool */
78	uint32_t pl_sp_id;	/* Subpool number within pool */
79	uint32_t pl_sp_devs;	/* Number of data partitions in this subpool */
80	uint32_t pl_sp_devid;	/* Partition number within subpool */
81	uint32_t pl_sp_type;	/* Partition type */
82	uint64_t pl_blocks;	/* Number of blocks in this partition */
83	uint32_t pl_striping;	/* Striping size within subpool */
84	/*
85	 * If the number of DMEP devices is zero, then the next field **
86	 * ** (pl_sp_dmepid) becomes the subpool ID for redirection.  In **
87	 * ** other words, if this subpool does not have the capability  **
88	 * ** to do DMEP, then it must specify which subpool will do it  **
89	 * ** in it's place
90	 */
91
92	/*
93	 * While the next 3 field are no longer used, they must stay to keep **
94	 * ** backward compatibility...........................................
95	 */
96	uint32_t pl_sp_dmepdevs;/* Number of dmep devices in this subpool */
97	uint32_t pl_sp_dmepid;	/* Dmep device number within subpool */
98	uint32_t pl_sp_weight;	/* if dmep dev, pref to using it */
99
100	uint32_t pl_minor;	/* the pool minor number */
101	uint32_t pl_padding;	/* reminder - think about alignment */
102
103	/*
104	 * Even though we're zeroing out 8k at the front of the disk before
105	 * writing the label, putting this in
106	 */
107	char pl_reserve[184];	/* bump the structure size out to 512 bytes */
108};
109
110struct pool_list {
111	struct dm_list list;
112	struct pool_disk pd;
113	struct physical_volume *pv;
114	struct id pv_uuid;
115	struct device *dev;
116};
117
118struct user_subpool {
119	uint32_t initialized;
120	uint32_t id;
121	uint32_t striping;
122	uint32_t num_devs;
123	uint32_t type;
124	uint32_t dummy;
125	struct user_device *devs;
126};
127
128struct user_device {
129	uint32_t initialized;
130	uint32_t sp_id;
131	uint32_t devid;
132	uint32_t dummy;
133	uint64_t blocks;
134	struct physical_volume *pv;
135};
136
137int read_pool_label(struct pool_list *pl, struct labeller *l,
138		    struct device *dev, char *buf, struct label **label);
139void pool_label_out(struct pool_disk *pl, void *buf);
140void pool_label_in(struct pool_disk *pl, void *buf);
141void get_pool_uuid(char *uuid, uint64_t poolid, uint32_t spid, uint32_t devid);
142int import_pool_vg(struct volume_group *vg, struct dm_pool *mem, struct dm_list *pls);
143int import_pool_lvs(struct volume_group *vg, struct dm_pool *mem,
144		    struct dm_list *pls);
145int import_pool_pvs(const struct format_type *fmt, struct volume_group *vg,
146		    struct dm_list *pvs, struct dm_pool *mem, struct dm_list *pls);
147int import_pool_pv(const struct format_type *fmt, struct dm_pool *mem,
148		   struct volume_group *vg, struct physical_volume *pv,
149		   struct pool_list *pl);
150int import_pool_segments(struct dm_list *lvs, struct dm_pool *mem,
151			 struct user_subpool *usp, int sp_count);
152int read_pool_pds(const struct format_type *fmt, const char *vgname,
153		  struct dm_pool *mem, struct dm_list *head);
154struct pool_list *read_pool_disk(const struct format_type *fmt,
155				 struct device *dev, struct dm_pool *mem,
156				 const char *vg_name);
157
158#endif				/* DISK_REP_POOL_FORMAT_H */
159