1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _MDS_STATE_H 27 #define _MDS_STATE_H 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 #include <sys/id_space.h> 34 #include <nfs/nfs4_db_impl.h> 35 #include <nfs/ds_prot.h> 36 #include <nfs/mds_odl.h> 37 #include <nfs/range.h> 38 39 typedef ds_guid_map ds_guid_map_t; 40 typedef ds_guid ds_guid_t; 41 42 #define MDS_MAX_LAYOUT_DEVS 16 43 44 /* 45 * A means to plop the internal uint32_t device 46 * id into an OTW 128 bit device id 47 */ 48 typedef union { 49 struct { 50 uint32_t pad0; 51 uint32_t pad1; 52 uint32_t pad2; 53 uint32_t did; 54 } i; 55 deviceid4 did4; 56 } ba_devid_t; 57 58 extern void mds_set_deviceid(id_t, deviceid4 *); 59 60 /* 61 * mds_mpd: 62 * 63 * The fields mdp_encoded_* are in fact the already 64 * encoded value for a nfsv4_1_file_layout_ds_addr4 65 */ 66 typedef struct mds_mpd { 67 rfs4_dbe_t *mpd_dbe; 68 id_t mpd_id; 69 uint_t mpd_encoded_len; 70 char *mpd_encoded_val; 71 list_t mpd_layouts_list; 72 } mds_mpd_t; 73 74 /* 75 * Used to build the reply to getdevicelist 76 */ 77 typedef struct mds_device_list { 78 int mdl_count; 79 deviceid4 *mdl_dl; 80 } mds_device_list_t; 81 82 typedef struct layout_core { 83 length4 lc_stripe_unit; 84 int lc_stripe_count; 85 mds_sid *lc_mds_sids; 86 } layout_core_t; 87 88 /* 89 * mds_layout has the information for the layout that has been 90 * allocated by the SPE. It is represented by the structure 91 * "struct odl" or on-disk-layout the odl will be plopped 92 * onto stable storage, once we know that a data-server 93 * has requested verification for an IO operation. 94 * -- 95 * stripe_unit gets plopped into a nfl_util4 in the returned 96 * layout information; 97 * -- 98 * lo_flags carries if we want dense or sparse data at the 99 * data-servers and also if we wish the NFS Client to commit 100 * through the MDS or Data-servers. 101 */ 102 typedef struct mds_layout { 103 rfs4_dbe_t *mlo_dbe; 104 int mlo_id; 105 layouttype4 mlo_type; 106 layout_core_t mlo_lc; 107 uint32_t mlo_flags; 108 rfs4_file_t *mlo_fp; 109 odl *mlo_odl; 110 mds_mpd_t *mlo_mpd; 111 id_t mlo_mpd_id; 112 list_node_t mpd_layouts_next; 113 } mds_layout_t; 114 115 #define LO_GRANTED 0x00000001 116 #define LO_RECALL_INPROG 0x00000002 117 #define LO_RECALLED 0x00000004 118 #define LO_RETURNED 0x00000008 119 120 typedef struct mds_layout_grant { 121 rfs4_dbe_t *lo_dbe; 122 stateid_t lo_stateid; 123 uint32_t lo_status; 124 kmutex_t lo_lock; 125 struct { 126 uint32_t lr_seqid; 127 uint32_t lr_reply; 128 } lo_rec; 129 mds_layout_t *lo_lop; 130 rfs4_client_t *lo_cp; 131 rfs4_file_t *lo_fp; 132 rfs41_grant_list_t lo_clientgrantlist; 133 rfs41_grant_list_t lo_grant_list; 134 nfs_range_t *lo_range; 135 } mds_layout_grant_t; 136 137 #define lor_seqid lo_rec.lr_seqid 138 #define lor_reply lo_rec.lr_reply 139 140 typedef struct mds_ever_grant { 141 rfs4_dbe_t *eg_dbe; 142 rfs4_client_t *eg_cp; 143 union { 144 fsid_t fsid; 145 int64_t key; 146 } eg_un; 147 } mds_ever_grant_t; 148 149 #define eg_fsid eg_un.fsid 150 #define eg_key eg_un.key 151 152 /* 153 * A ds_owner has a list of ds_addrlist entries and 154 * a list of ds_guid entries. As an entry is added into 155 * a list, it will bump the refcnts in both the ds_owner 156 * and itself. It does this to prevent both references 157 * from becoming invalid. 158 * 159 * This sounds nasty and recursive. It is. If an entry 160 * destroy function is called without going through the 161 * external linked list release functions, well, this 162 * is your only warning not to do that. 163 */ 164 typedef struct { 165 rfs4_dbe_t *dbe; 166 time_t last_access; 167 char *identity; 168 ds_id ds_id; 169 ds_verifier verifier; 170 uint32_t dsi_flags; 171 list_t ds_addrlist_list; 172 list_t ds_guid_list; 173 } ds_owner_t; 174 175 /* 176 * Mapping of MDS_SID(s) (the MDS storage identifier) to 177 * ds_guid; Saved on disk, held in memory for replies to 178 * DS_REPORTAVAIL and DS_MAP_MDSSID. 179 */ 180 typedef struct { 181 rfs4_dbe_t *dbe; 182 ds_guid_map_t ds_map; 183 } mds_mapzap_t; 184 185 #define MDS_DSI_REBOOTED 1 186 187 /* 188 * Allow 4 bits for ds_validuse, the rest is 189 * for our use. 190 */ 191 #define MDS_DEV_DS_MASK 0x0000000F 192 #define MDS_DEV_SKIP_ME 0x00000010 193 #define MDS_DEV_NEW 0x00000020 194 195 #define MDS_SET_DS_FLAGS(dst, flg) \ 196 dst = (dst & ~MDS_DEV_DS_MASK) | (MDS_DEV_DS_MASK & flg); 197 198 /* 199 * ds_addrlist: 200 * 201 * This list is updated via the control-protocol 202 * message DS_REPORTAVAIL. 203 */ 204 typedef struct { 205 rfs4_dbe_t *dbe; 206 netaddr4 dev_addr; 207 struct knetconfig *dev_knc; 208 struct netbuf *dev_nb; 209 uint_t dev_flags; 210 uint32_t ds_port_key; 211 uint64_t ds_addr_key; 212 ds_owner_t *ds_owner; 213 list_node_t ds_addrlist_next; 214 } ds_addrlist_t; 215 216 /* 217 * Tracks the state 'handed out' to the data-server. 218 */ 219 typedef struct { 220 rfs4_dbe_t *dbe; 221 ds_owner_t *ds_owner; 222 } mds_ds_state_t; 223 224 struct mds_adddev_args { 225 int dev_id; 226 char *dev_netid; 227 char *dev_addr; 228 char *ds_addr; 229 }; 230 231 /* 232 * Identify the dataset... 233 */ 234 235 236 /* 237 * Tracks the mds_sid to data-server guid, and 238 * associated attributes. 239 */ 240 typedef struct { 241 rfs4_dbe_t *dbe; 242 ds_owner_t *ds_owner; 243 list_node_t ds_guid_next; 244 ds_guid_t ds_guid; /* This is the mds_dataset_id */ 245 utf8string ds_dataset_name; /* Name of the dataset */ 246 uint_t ds_attr_len; 247 ds_zfsattr *ds_attr_val; /* XXX Should this be more general? */ 248 } ds_guid_info_t; 249 250 /* 251 * A small structure passed in the ds_storinfo create 252 * entry. 253 */ 254 typedef struct { 255 struct ds_storinfo *si; 256 ds_owner_t *ds_owner; 257 } pinfo_create_t; 258 259 extern int mds_get_odl(vnode_t *, mds_layout_t **); 260 extern void mds_xdr_devicelist(rfs4_entry_t, void *); 261 extern ds_addrlist_t *mds_find_ds_addrlist(nfs_server_instance_t *, uint32_t); 262 extern ds_addrlist_t *mds_find_ds_addrlist_by_mds_sid(nfs_server_instance_t *, 263 mds_sid *); 264 extern ds_addrlist_t *mds_find_ds_addrlist_by_uaddr(nfs_server_instance_t *, 265 char *); 266 extern void mds_ds_addrlist_rele(ds_addrlist_t *); 267 extern ds_guid_info_t *mds_find_ds_guid_info_by_id(ds_guid_t *guid); 268 extern int uaddr2sockaddr(int, char *, void *, in_port_t *); 269 extern int mds_put_layout(mds_layout_t *, vnode_t *); 270 271 #ifdef __cplusplus 272 } 273 #endif 274 275 #endif /* _MDS_STATE_H */ 276