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 _SYS_DSERV_IMPL_H 27 #define _SYS_DSERV_IMPL_H 28 29 #include <sys/vfs.h> 30 #include <sys/list.h> 31 #include <sys/avl.h> 32 #include <nfs/nfs4_kprot.h> 33 #include <nfs/nfs41_kprot.h> 34 #include <nfs/nfs4.h> 35 #include <sys/dmu.h> 36 #include <nfs/ds_prot.h> 37 #include <nfs/nnode.h> 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 #define DSERV_MAXREAD (1 * 1024 * 1024) 44 #define DS_TO_MDS_CTRL_PROTO_RETRIES 5 45 #define CTLDS_TIMEO 60 /* seconds */ 46 47 kmem_cache_t *dserv_open_mdsfs_objset_cache; 48 49 /* 50 * This data structure creates a unique identifer for a dataset for the 51 * data server. 52 */ 53 typedef struct dserv_guid { 54 uint64_t dg_zpool_guid; /* SPA GUID */ 55 uint64_t dg_objset_guid; /* Object set ID */ 56 } dserv_guid_t; 57 58 /* 59 * This data structure is used to store the mapping of a MDS Storage ID 60 * to a real data server guid (zpool id + id of root pNFS object set). 61 */ 62 typedef struct mds_sid_map { 63 mds_sid msm_mds_storid; 64 dserv_guid_t msm_ds_guid; 65 list_node_t msm_mds_sid_map_node; 66 } mds_sid_map_t; 67 68 /* 69 * This data structure stores the list of open root object sets that a 70 * data server has. 71 * 72 * oro_objsetname - name of the root pNFS objset 73 * 74 * oro_osp - pointer to the open root pNFS object set 75 * 76 * oro_ds_guid - the real zpool guid assigned by the SPA and the real objset 77 * guid assigned by the DMU. 78 * 79 * oro_mds_zpool_id - The id for this root objset provided by the MDS upon 80 * response to DS_REPORTAVAIL. This is the value that will be 81 * encoded in the file handle used between the client and data servers. 82 * 83 * oro_open_mdsfs_objsets - The open child, fsid object sets for this root 84 * pNFS object set. 85 * 86 * oro_open_objset_node - the linked list node 87 */ 88 typedef struct open_root_objset { 89 char oro_objsetname[MAXPATHLEN]; 90 objset_t *oro_osp; 91 dserv_guid_t oro_ds_guid; 92 list_t oro_open_mdsfs_objsets; 93 list_node_t oro_open_root_objset_node; 94 } open_root_objset_t; 95 96 typedef uint32_t fsid_objset_flags; 97 98 typedef struct open_mdsfs_objset { 99 mds_dataset_id omo_dataset_id; 100 objset_t *omo_osp; 101 fsid_objset_flags omo_flags; 102 list_node_t omo_open_mdsfs_objset_node; 103 } open_mdsfs_objset_t; 104 105 typedef struct dserv_uaddr { 106 char *du_addr; 107 char *du_proto; 108 list_node_t du_list; 109 } dserv_uaddr_t; 110 111 /* 112 * Persistent portion of nnode private data. 113 * It is stored in the "bonus buffer" of the file. 114 */ 115 typedef struct dserv_nnode_data_phys { 116 uint64_t dp_size; /* file size */ 117 } dserv_nnode_data_phys_t; 118 119 /* 120 * nnode private data 121 */ 122 123 typedef struct { 124 mds_sid *dnk_sid; 125 nfs41_fid_t *dnk_fid; 126 nfs41_fid_t dnk_real_fid; 127 } dserv_nnode_key_t; 128 129 typedef struct dserv_nnode_data { 130 krwlock_t dnd_rwlock; 131 uint32_t dnd_flags; 132 133 mds_ds_fh *dnd_fh; 134 nfs41_fid_t *dnd_fid; 135 objset_t *dnd_objset; 136 uint64_t dnd_object; /* dmu object id */ 137 uint32_t dnd_blksize; /* object block size */ 138 dserv_nnode_data_phys_t *dnd_phys; /* ptr to persistent attrs */ 139 dmu_buf_t *dnd_dbuf; /* buffer containing dnd_phys */ 140 } dserv_nnode_data_t; 141 #define DSERV_NNODE_FLAG_OBJSET 0x01 142 #define DSERV_NNODE_FLAG_OBJECT 0x02 143 144 typedef struct dserv_nnode_state { 145 mds_ds_fh *fh; 146 } dserv_nnode_state_t; 147 148 /* 149 * Server structures 150 */ 151 typedef struct dserv_compound_state { 152 nfsstat4 *dcs_statusp; 153 int *dcs_continue; 154 nnode_t *dcs_nnode; 155 } dserv_compound_state_t; 156 157 typedef struct { 158 CLIENT *dmh_client; 159 list_node_t dmh_list; 160 } dserv_mds_handle_t; 161 162 typedef struct { 163 pid_t dmi_pid; 164 time_t dmi_start_time; 165 uint64_t dmi_ds_id; 166 uint64_t dmi_verifier; 167 char *dmi_name; 168 avl_node_t dmi_avl; 169 krwlock_t dmi_inst_lock; 170 kmutex_t dmi_content_lock; 171 uint32_t dmi_flags; 172 struct netbuf dmi_nb; 173 struct knetconfig dmi_knc; 174 char *dmi_mds_addr; 175 char *dmi_mds_netid; 176 list_t dmi_datasets; 177 list_t dmi_mds_sids; 178 list_t dmi_uaddrs; 179 list_t dmi_handles; 180 boolean_t dmi_teardown_in_progress; 181 kmutex_t dmi_zap_lock; 182 boolean_t dmi_recov_in_progress; 183 ds_verifier dmi_mds_boot_verifier; 184 } dserv_mds_instance_t; 185 186 #define DSERV_MDS_INSTANCE_NET_VALID 0x01 187 188 /* 189 * Useful macros 190 */ 191 192 #define DSERV_AVL_RETURN(rc) \ 193 if (rc < 0) \ 194 return (-1); \ 195 if (rc > 0) \ 196 return (1); 197 198 /* 199 * Function declarations 200 */ 201 void dserv_server_setup(void); 202 void dserv_server_teardown(void); 203 void dserv_mds_setup(void); 204 void dserv_mds_teardown(void); 205 int dserv_mds_instance_teardown(); 206 int dserv_mds_setmds(char *, char *); 207 int dserv_mds_addobjset(const char *); 208 int dserv_mds_addport(const char *, const char *, const char *); 209 int dserv_mds_reportavail(void); 210 nfsstat4 dserv_mds_checkstate(void *, compound_state_t *, int mode, 211 stateid4 *, bool_t, bool_t *, bool_t, caller_context_t *, clientid4 *); 212 dserv_mds_instance_t *dserv_mds_get_my_instance(void); 213 int dserv_instance_enter(krw_t, boolean_t, dserv_mds_instance_t **, pid_t *); 214 void dserv_instance_exit(dserv_mds_instance_t *); 215 char *dserv_strdup(const char *); 216 void dserv_strfree(char *); 217 int dserv_mds_do_reportavail(dserv_mds_instance_t *, ds_status *); 218 int dserv_mds_exibi(dserv_mds_instance_t *, ds_status *); 219 void dserv_mds_heartbeat_thread(); 220 221 /* 222 * Globals 223 */ 224 225 extern int dserv_debug; 226 227 #ifdef __cplusplus 228 } 229 #endif 230 231 #endif /* _SYS_DSERV_IMPL_H */ 232