1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2003 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include <stdio.h> 30*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 31*7c478bd9Sstevel@tonic-gate #include <string.h> 32*7c478bd9Sstevel@tonic-gate #include <errno.h> 33*7c478bd9Sstevel@tonic-gate #include <fcntl.h> 34*7c478bd9Sstevel@tonic-gate #include <kvm.h> 35*7c478bd9Sstevel@tonic-gate #include <kstat.h> 36*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 37*7c478bd9Sstevel@tonic-gate #include <sys/mnttab.h> 38*7c478bd9Sstevel@tonic-gate #include <sys/mntent.h> 39*7c478bd9Sstevel@tonic-gate #include <nfs/nfs.h> 40*7c478bd9Sstevel@tonic-gate #include <nfs/nfs_clnt.h> 41*7c478bd9Sstevel@tonic-gate #include <sys/mkdev.h> 42*7c478bd9Sstevel@tonic-gate #include <inttypes.h> 43*7c478bd9Sstevel@tonic-gate #include <sys/stat.h> 44*7c478bd9Sstevel@tonic-gate 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate #include "libfsmgt.h" 47*7c478bd9Sstevel@tonic-gate #include "replica.h" 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate #define IGNORE 0 50*7c478bd9Sstevel@tonic-gate #define DEV 1 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate /* 53*7c478bd9Sstevel@tonic-gate * Private variables 54*7c478bd9Sstevel@tonic-gate */ 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate static char *mntopts[] = { MNTOPT_IGNORE, MNTOPT_DEV, NULL }; 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate /* 59*7c478bd9Sstevel@tonic-gate * Private method declarations 60*7c478bd9Sstevel@tonic-gate */ 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate static int ignore(char *); 63*7c478bd9Sstevel@tonic-gate static int get_kstat_info(nfs_mntlist_t *, int *); 64*7c478bd9Sstevel@tonic-gate static nfs_mntlist_t *get_mount_data(fs_mntlist_t *, int *); 65*7c478bd9Sstevel@tonic-gate static nfs_mntlist_t *get_nfs_info(fs_mntlist_t *, int *); 66*7c478bd9Sstevel@tonic-gate static nfs_mntlist_t *kstat_mount(nfs_mntlist_t *, kstat_t *); 67*7c478bd9Sstevel@tonic-gate static int load_kstat_data(kstat_ctl_t *, nfs_mntlist_t *, kstat_t *, int *); 68*7c478bd9Sstevel@tonic-gate static kid_t safe_kstat_read(kstat_ctl_t *, kstat_t *, void *, int *); 69*7c478bd9Sstevel@tonic-gate 70*7c478bd9Sstevel@tonic-gate /* 71*7c478bd9Sstevel@tonic-gate * Public methods 72*7c478bd9Sstevel@tonic-gate */ 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate void 75*7c478bd9Sstevel@tonic-gate nfs_free_mntinfo_list(nfs_mntlist_t *list) 76*7c478bd9Sstevel@tonic-gate { 77*7c478bd9Sstevel@tonic-gate nfs_mntlist_t *tmp; 78*7c478bd9Sstevel@tonic-gate int i; 79*7c478bd9Sstevel@tonic-gate 80*7c478bd9Sstevel@tonic-gate while (list != NULL) { 81*7c478bd9Sstevel@tonic-gate free(list->nml_resource); 82*7c478bd9Sstevel@tonic-gate free(list->nml_mountp); 83*7c478bd9Sstevel@tonic-gate free(list->nml_fstype); 84*7c478bd9Sstevel@tonic-gate free(list->nml_mntopts); 85*7c478bd9Sstevel@tonic-gate free(list->nml_time); 86*7c478bd9Sstevel@tonic-gate for (i = 0; i < list->nml_failovercount; i++) { 87*7c478bd9Sstevel@tonic-gate if (list->nml_failoverlist[i] != NULL) 88*7c478bd9Sstevel@tonic-gate free(list->nml_failoverlist[i]); 89*7c478bd9Sstevel@tonic-gate } 90*7c478bd9Sstevel@tonic-gate free(list->nml_failoverlist); 91*7c478bd9Sstevel@tonic-gate free(list->nml_securitymode); 92*7c478bd9Sstevel@tonic-gate tmp = list->next; 93*7c478bd9Sstevel@tonic-gate free(list); 94*7c478bd9Sstevel@tonic-gate list = tmp; 95*7c478bd9Sstevel@tonic-gate } 96*7c478bd9Sstevel@tonic-gate } /* nfs_free_mntinfo_list */ 97*7c478bd9Sstevel@tonic-gate 98*7c478bd9Sstevel@tonic-gate nfs_mntlist_t * 99*7c478bd9Sstevel@tonic-gate nfs_get_filtered_mount_list(char *resource, char *mountp, char *mntopts, 100*7c478bd9Sstevel@tonic-gate char *time, boolean_t find_overlays, int *errp) { 101*7c478bd9Sstevel@tonic-gate 102*7c478bd9Sstevel@tonic-gate fs_mntlist_t *fs_mount_list; 103*7c478bd9Sstevel@tonic-gate nfs_mntlist_t *nfs_mount_list; 104*7c478bd9Sstevel@tonic-gate 105*7c478bd9Sstevel@tonic-gate fs_mount_list = fs_get_filtered_mount_list(resource, mountp, 106*7c478bd9Sstevel@tonic-gate MNTTYPE_NFS, mntopts, time, find_overlays, errp); 107*7c478bd9Sstevel@tonic-gate if (fs_mount_list == NULL) { 108*7c478bd9Sstevel@tonic-gate return (NULL); 109*7c478bd9Sstevel@tonic-gate } 110*7c478bd9Sstevel@tonic-gate 111*7c478bd9Sstevel@tonic-gate if ((nfs_mount_list = get_nfs_info(fs_mount_list, errp)) == NULL) { 112*7c478bd9Sstevel@tonic-gate fs_free_mount_list(fs_mount_list); 113*7c478bd9Sstevel@tonic-gate return (NULL); 114*7c478bd9Sstevel@tonic-gate } 115*7c478bd9Sstevel@tonic-gate 116*7c478bd9Sstevel@tonic-gate fs_free_mount_list(fs_mount_list); 117*7c478bd9Sstevel@tonic-gate return (nfs_mount_list); 118*7c478bd9Sstevel@tonic-gate } /* nfs_get_filtered_mount_list */ 119*7c478bd9Sstevel@tonic-gate 120*7c478bd9Sstevel@tonic-gate nfs_mntlist_t * 121*7c478bd9Sstevel@tonic-gate nfs_get_mounts_by_mntopt(char *mntopt, boolean_t find_overlays, int *errp) 122*7c478bd9Sstevel@tonic-gate { 123*7c478bd9Sstevel@tonic-gate fs_mntlist_t *fs_mount_list; 124*7c478bd9Sstevel@tonic-gate nfs_mntlist_t *nfs_mount_list; 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate fs_mount_list = fs_get_mounts_by_mntopt(mntopt, find_overlays, errp); 127*7c478bd9Sstevel@tonic-gate if (fs_mount_list == NULL) { 128*7c478bd9Sstevel@tonic-gate return (NULL); 129*7c478bd9Sstevel@tonic-gate } 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate if ((nfs_mount_list = get_nfs_info(fs_mount_list, errp)) == NULL) { 132*7c478bd9Sstevel@tonic-gate fs_free_mount_list(fs_mount_list); 133*7c478bd9Sstevel@tonic-gate return (NULL); 134*7c478bd9Sstevel@tonic-gate } 135*7c478bd9Sstevel@tonic-gate 136*7c478bd9Sstevel@tonic-gate fs_free_mount_list(fs_mount_list); 137*7c478bd9Sstevel@tonic-gate return (nfs_mount_list); 138*7c478bd9Sstevel@tonic-gate } /* nfs_get_mount_by_mntopt */ 139*7c478bd9Sstevel@tonic-gate 140*7c478bd9Sstevel@tonic-gate nfs_mntlist_t * 141*7c478bd9Sstevel@tonic-gate nfs_get_mount_list(int *errp) 142*7c478bd9Sstevel@tonic-gate { 143*7c478bd9Sstevel@tonic-gate fs_mntlist_t *fs_mount_list; 144*7c478bd9Sstevel@tonic-gate nfs_mntlist_t *nfs_mount_list; 145*7c478bd9Sstevel@tonic-gate boolean_t find_overlays = B_TRUE; 146*7c478bd9Sstevel@tonic-gate 147*7c478bd9Sstevel@tonic-gate if ((fs_mount_list = fs_get_mount_list(find_overlays, errp)) == NULL) { 148*7c478bd9Sstevel@tonic-gate fprintf(stderr, "nfs_mntinfo: Can't access mnttab. %s\n", 149*7c478bd9Sstevel@tonic-gate strerror(*errp)); 150*7c478bd9Sstevel@tonic-gate return (NULL); 151*7c478bd9Sstevel@tonic-gate } 152*7c478bd9Sstevel@tonic-gate 153*7c478bd9Sstevel@tonic-gate if ((nfs_mount_list = get_nfs_info(fs_mount_list, errp)) == NULL) { 154*7c478bd9Sstevel@tonic-gate fs_free_mount_list(fs_mount_list); 155*7c478bd9Sstevel@tonic-gate return (NULL); 156*7c478bd9Sstevel@tonic-gate } 157*7c478bd9Sstevel@tonic-gate 158*7c478bd9Sstevel@tonic-gate fs_free_mount_list(fs_mount_list); 159*7c478bd9Sstevel@tonic-gate return (nfs_mount_list); 160*7c478bd9Sstevel@tonic-gate } /* nfs_get_mount_list */ 161*7c478bd9Sstevel@tonic-gate 162*7c478bd9Sstevel@tonic-gate /* 163*7c478bd9Sstevel@tonic-gate * Private methods 164*7c478bd9Sstevel@tonic-gate */ 165*7c478bd9Sstevel@tonic-gate 166*7c478bd9Sstevel@tonic-gate static int 167*7c478bd9Sstevel@tonic-gate get_kstat_info(nfs_mntlist_t *nfs_mntinfo, int *errp) 168*7c478bd9Sstevel@tonic-gate { 169*7c478bd9Sstevel@tonic-gate kstat_ctl_t *libkstat_cookie = NULL; 170*7c478bd9Sstevel@tonic-gate nfs_mntlist_t *mrp; 171*7c478bd9Sstevel@tonic-gate kstat_t *ksp; 172*7c478bd9Sstevel@tonic-gate 173*7c478bd9Sstevel@tonic-gate if ((libkstat_cookie = kstat_open()) == NULL) { 174*7c478bd9Sstevel@tonic-gate *errp = errno; 175*7c478bd9Sstevel@tonic-gate fprintf(stderr, 176*7c478bd9Sstevel@tonic-gate "nfs_mntinfo: kstat_open(): can't open /dev/kstat.\n"); 177*7c478bd9Sstevel@tonic-gate return (-1); 178*7c478bd9Sstevel@tonic-gate } 179*7c478bd9Sstevel@tonic-gate /* 180*7c478bd9Sstevel@tonic-gate * Each kstat consists of header and data sections that are 181*7c478bd9Sstevel@tonic-gate * connected as a "chain" or linked list of kstat stuctures. 182*7c478bd9Sstevel@tonic-gate * The kc_chain used here is the pointer to the global kstat 183*7c478bd9Sstevel@tonic-gate * chain (or the head of the chain of kstat's). 184*7c478bd9Sstevel@tonic-gate */ 185*7c478bd9Sstevel@tonic-gate for (ksp = libkstat_cookie->kc_chain; ksp; ksp = ksp->ks_next) { 186*7c478bd9Sstevel@tonic-gate if ((ksp->ks_type == KSTAT_TYPE_RAW) && 187*7c478bd9Sstevel@tonic-gate (strcmp(ksp->ks_module, "nfs") == 0) && 188*7c478bd9Sstevel@tonic-gate (strcmp(ksp->ks_name, "mntinfo") == 0) && 189*7c478bd9Sstevel@tonic-gate ((mrp = kstat_mount(nfs_mntinfo, ksp)) != NULL)) { 190*7c478bd9Sstevel@tonic-gate if (load_kstat_data(libkstat_cookie, mrp, ksp, errp) 191*7c478bd9Sstevel@tonic-gate == -1) { 192*7c478bd9Sstevel@tonic-gate nfs_free_mntinfo_list(mrp); 193*7c478bd9Sstevel@tonic-gate return (-1); 194*7c478bd9Sstevel@tonic-gate } 195*7c478bd9Sstevel@tonic-gate } 196*7c478bd9Sstevel@tonic-gate } 197*7c478bd9Sstevel@tonic-gate return (0); 198*7c478bd9Sstevel@tonic-gate } /* get_kstat_info */ 199*7c478bd9Sstevel@tonic-gate 200*7c478bd9Sstevel@tonic-gate static int 201*7c478bd9Sstevel@tonic-gate load_kstat_data(kstat_ctl_t *libkstat_cookie, nfs_mntlist_t *mrp, 202*7c478bd9Sstevel@tonic-gate kstat_t *ksp, int *errp) 203*7c478bd9Sstevel@tonic-gate { 204*7c478bd9Sstevel@tonic-gate struct mntinfo_kstat mik; 205*7c478bd9Sstevel@tonic-gate seconfig_t nfs_sec; 206*7c478bd9Sstevel@tonic-gate 207*7c478bd9Sstevel@tonic-gate if (mrp == 0) { 208*7c478bd9Sstevel@tonic-gate return (0); 209*7c478bd9Sstevel@tonic-gate } 210*7c478bd9Sstevel@tonic-gate 211*7c478bd9Sstevel@tonic-gate if (safe_kstat_read(libkstat_cookie, ksp, &mik, errp) == -1) { 212*7c478bd9Sstevel@tonic-gate return (-1); 213*7c478bd9Sstevel@tonic-gate } 214*7c478bd9Sstevel@tonic-gate 215*7c478bd9Sstevel@tonic-gate if (strlcpy(mrp->nml_proto, mik.mik_proto, KNC_STRSIZE) 216*7c478bd9Sstevel@tonic-gate >= KNC_STRSIZE) { 217*7c478bd9Sstevel@tonic-gate *errp = errno; 218*7c478bd9Sstevel@tonic-gate return (-1); 219*7c478bd9Sstevel@tonic-gate } 220*7c478bd9Sstevel@tonic-gate if (strlcpy(mrp->nml_curserver, mik.mik_curserver, SYS_NMLN) 221*7c478bd9Sstevel@tonic-gate >= SYS_NMLN) { 222*7c478bd9Sstevel@tonic-gate *errp = errno; 223*7c478bd9Sstevel@tonic-gate return (-1); 224*7c478bd9Sstevel@tonic-gate } 225*7c478bd9Sstevel@tonic-gate mrp->nml_vers = mik.mik_vers; 226*7c478bd9Sstevel@tonic-gate /* 227*7c478bd9Sstevel@tonic-gate * get the secmode name from /etc/nfssec.conf. 228*7c478bd9Sstevel@tonic-gate */ 229*7c478bd9Sstevel@tonic-gate if (!nfs_getseconfig_bynumber(mik.mik_secmod, &nfs_sec)) { 230*7c478bd9Sstevel@tonic-gate mrp->nml_securitymode = strdup(nfs_sec.sc_name); 231*7c478bd9Sstevel@tonic-gate } else { 232*7c478bd9Sstevel@tonic-gate mrp->nml_securitymode = NULL; 233*7c478bd9Sstevel@tonic-gate } 234*7c478bd9Sstevel@tonic-gate mrp->nml_curread = mik.mik_curread; 235*7c478bd9Sstevel@tonic-gate mrp->nml_curwrite = mik.mik_curwrite; 236*7c478bd9Sstevel@tonic-gate mrp->nml_timeo = mik.mik_timeo; 237*7c478bd9Sstevel@tonic-gate mrp->nml_retrans = mik.mik_retrans; 238*7c478bd9Sstevel@tonic-gate mrp->nml_acregmin = mik.mik_acregmin; 239*7c478bd9Sstevel@tonic-gate mrp->nml_acregmax = mik.mik_acregmax; 240*7c478bd9Sstevel@tonic-gate mrp->nml_acdirmin = mik.mik_acdirmin; 241*7c478bd9Sstevel@tonic-gate mrp->nml_acdirmax = mik.mik_acdirmax; 242*7c478bd9Sstevel@tonic-gate mrp->nml_hard = 243*7c478bd9Sstevel@tonic-gate ((mik.mik_flags & MI_HARD) ? B_TRUE : B_FALSE); 244*7c478bd9Sstevel@tonic-gate mrp->nml_intr = 245*7c478bd9Sstevel@tonic-gate ((mik.mik_flags & MI_INT) ? B_TRUE : B_FALSE); 246*7c478bd9Sstevel@tonic-gate mrp->nml_noac = 247*7c478bd9Sstevel@tonic-gate ((mik.mik_flags & MI_NOAC) ? B_TRUE : B_FALSE); 248*7c478bd9Sstevel@tonic-gate mrp->nml_nocto = 249*7c478bd9Sstevel@tonic-gate ((mik.mik_flags & MI_NOCTO) ? B_TRUE : B_FALSE); 250*7c478bd9Sstevel@tonic-gate mrp->nml_grpid = 251*7c478bd9Sstevel@tonic-gate ((mik.mik_flags & MI_GRPID) ? B_TRUE : B_FALSE); 252*7c478bd9Sstevel@tonic-gate mrp->nml_directio = 253*7c478bd9Sstevel@tonic-gate ((mik.mik_flags & MI_DIRECTIO) ? B_TRUE : B_FALSE); 254*7c478bd9Sstevel@tonic-gate mrp->nml_xattr = 255*7c478bd9Sstevel@tonic-gate ((mik.mik_flags & MI_EXTATTR) ? B_TRUE : B_FALSE); 256*7c478bd9Sstevel@tonic-gate return (0); 257*7c478bd9Sstevel@tonic-gate } 258*7c478bd9Sstevel@tonic-gate 259*7c478bd9Sstevel@tonic-gate nfs_mntlist_t * 260*7c478bd9Sstevel@tonic-gate kstat_mount(nfs_mntlist_t *nfs_mntinfo, kstat_t *ksp) { 261*7c478bd9Sstevel@tonic-gate nfs_mntlist_t *mrp; 262*7c478bd9Sstevel@tonic-gate /* 263*7c478bd9Sstevel@tonic-gate * MAXMIN is used to retrieve the minor number 264*7c478bd9Sstevel@tonic-gate * which is compared to the kstat instance. 265*7c478bd9Sstevel@tonic-gate * If they are the same then this is an instance 266*7c478bd9Sstevel@tonic-gate * for which mount information is needed. 267*7c478bd9Sstevel@tonic-gate * MAXMIN is the maximum minor number and is 268*7c478bd9Sstevel@tonic-gate * defined in mkdev.h. 269*7c478bd9Sstevel@tonic-gate */ 270*7c478bd9Sstevel@tonic-gate mrp = nfs_mntinfo; 271*7c478bd9Sstevel@tonic-gate while ((mrp != NULL) && 272*7c478bd9Sstevel@tonic-gate ((mrp->nml_fsid & MAXMIN) != ksp->ks_instance)) { 273*7c478bd9Sstevel@tonic-gate mrp = mrp->next; 274*7c478bd9Sstevel@tonic-gate } 275*7c478bd9Sstevel@tonic-gate return (mrp); 276*7c478bd9Sstevel@tonic-gate } 277*7c478bd9Sstevel@tonic-gate 278*7c478bd9Sstevel@tonic-gate static nfs_mntlist_t * 279*7c478bd9Sstevel@tonic-gate get_nfs_info(fs_mntlist_t *fslist, int *errp) { 280*7c478bd9Sstevel@tonic-gate nfs_mntlist_t *mrp = NULL; 281*7c478bd9Sstevel@tonic-gate nfs_mntlist_t *headptr = NULL; 282*7c478bd9Sstevel@tonic-gate nfs_mntlist_t *tailptr = NULL; 283*7c478bd9Sstevel@tonic-gate fs_mntlist_t *fsmnt_list; 284*7c478bd9Sstevel@tonic-gate 285*7c478bd9Sstevel@tonic-gate for (fsmnt_list = fslist; fsmnt_list; fsmnt_list = fsmnt_list->next) { 286*7c478bd9Sstevel@tonic-gate /* ignore non "nfs" and the "ignore" entries */ 287*7c478bd9Sstevel@tonic-gate 288*7c478bd9Sstevel@tonic-gate if ((strcmp(fsmnt_list->fstype, MNTTYPE_NFS) != 0) || 289*7c478bd9Sstevel@tonic-gate (ignore(fsmnt_list->mntopts))) { 290*7c478bd9Sstevel@tonic-gate continue; 291*7c478bd9Sstevel@tonic-gate } 292*7c478bd9Sstevel@tonic-gate 293*7c478bd9Sstevel@tonic-gate if ((mrp = get_mount_data(fsmnt_list, errp)) == NULL) { 294*7c478bd9Sstevel@tonic-gate nfs_free_mntinfo_list(headptr); 295*7c478bd9Sstevel@tonic-gate return (NULL); 296*7c478bd9Sstevel@tonic-gate } 297*7c478bd9Sstevel@tonic-gate if (tailptr == NULL) { 298*7c478bd9Sstevel@tonic-gate headptr = mrp; 299*7c478bd9Sstevel@tonic-gate tailptr = mrp; 300*7c478bd9Sstevel@tonic-gate tailptr->next = NULL; 301*7c478bd9Sstevel@tonic-gate } else { 302*7c478bd9Sstevel@tonic-gate tailptr->next = mrp; 303*7c478bd9Sstevel@tonic-gate tailptr = mrp; 304*7c478bd9Sstevel@tonic-gate tailptr->next = NULL; 305*7c478bd9Sstevel@tonic-gate } 306*7c478bd9Sstevel@tonic-gate } 307*7c478bd9Sstevel@tonic-gate 308*7c478bd9Sstevel@tonic-gate if (get_kstat_info(headptr, errp) == -1) { 309*7c478bd9Sstevel@tonic-gate nfs_free_mntinfo_list(mrp); 310*7c478bd9Sstevel@tonic-gate return (NULL); 311*7c478bd9Sstevel@tonic-gate } 312*7c478bd9Sstevel@tonic-gate return (headptr); 313*7c478bd9Sstevel@tonic-gate 314*7c478bd9Sstevel@tonic-gate } /* get_nfs_info */ 315*7c478bd9Sstevel@tonic-gate 316*7c478bd9Sstevel@tonic-gate 317*7c478bd9Sstevel@tonic-gate static nfs_mntlist_t * 318*7c478bd9Sstevel@tonic-gate get_mount_data(fs_mntlist_t *fsmnt_list, int *errp) { 319*7c478bd9Sstevel@tonic-gate struct replica *rep_list; /* defined in replica.h */ 320*7c478bd9Sstevel@tonic-gate nfs_mntlist_t *mrp; 321*7c478bd9Sstevel@tonic-gate int i, server_count = 0; 322*7c478bd9Sstevel@tonic-gate struct stat stat_buf; 323*7c478bd9Sstevel@tonic-gate 324*7c478bd9Sstevel@tonic-gate if ((mrp = malloc(sizeof (nfs_mntlist_t))) == 0) { 325*7c478bd9Sstevel@tonic-gate *errp = errno; 326*7c478bd9Sstevel@tonic-gate return (NULL); 327*7c478bd9Sstevel@tonic-gate } 328*7c478bd9Sstevel@tonic-gate 329*7c478bd9Sstevel@tonic-gate if ((stat(fsmnt_list->mountp, &stat_buf) == 0)) { 330*7c478bd9Sstevel@tonic-gate mrp->nml_fsid = stat_buf.st_dev; 331*7c478bd9Sstevel@tonic-gate } else { 332*7c478bd9Sstevel@tonic-gate *errp = errno; 333*7c478bd9Sstevel@tonic-gate nfs_free_mntinfo_list(mrp); 334*7c478bd9Sstevel@tonic-gate return (NULL); 335*7c478bd9Sstevel@tonic-gate } 336*7c478bd9Sstevel@tonic-gate 337*7c478bd9Sstevel@tonic-gate if ((mrp->nml_resource = strdup(fsmnt_list->resource)) 338*7c478bd9Sstevel@tonic-gate == NULL) { 339*7c478bd9Sstevel@tonic-gate *errp = errno; 340*7c478bd9Sstevel@tonic-gate nfs_free_mntinfo_list(mrp); 341*7c478bd9Sstevel@tonic-gate return (NULL); 342*7c478bd9Sstevel@tonic-gate } 343*7c478bd9Sstevel@tonic-gate if ((rep_list = 344*7c478bd9Sstevel@tonic-gate parse_replica(mrp->nml_resource, &server_count)) == NULL) { 345*7c478bd9Sstevel@tonic-gate nfs_free_mntinfo_list(mrp); 346*7c478bd9Sstevel@tonic-gate return (NULL); 347*7c478bd9Sstevel@tonic-gate } 348*7c478bd9Sstevel@tonic-gate if ((mrp->nml_failoverlist = 349*7c478bd9Sstevel@tonic-gate calloc(server_count, sizeof (char *))) == NULL) { 350*7c478bd9Sstevel@tonic-gate nfs_free_mntinfo_list(mrp); 351*7c478bd9Sstevel@tonic-gate return (NULL); 352*7c478bd9Sstevel@tonic-gate } 353*7c478bd9Sstevel@tonic-gate for (i = 0; i < server_count; i++) { 354*7c478bd9Sstevel@tonic-gate mrp->nml_failoverlist[i] = 355*7c478bd9Sstevel@tonic-gate malloc(strlen(rep_list[i].host) + strlen(":") + 356*7c478bd9Sstevel@tonic-gate strlen(rep_list[i].path) + 2); 357*7c478bd9Sstevel@tonic-gate if (!mrp->nml_failoverlist[i]) { 358*7c478bd9Sstevel@tonic-gate nfs_free_mntinfo_list(mrp); 359*7c478bd9Sstevel@tonic-gate return (NULL); 360*7c478bd9Sstevel@tonic-gate } 361*7c478bd9Sstevel@tonic-gate sprintf(mrp->nml_failoverlist[i], "%s%s%s", 362*7c478bd9Sstevel@tonic-gate rep_list[i].host, ":", rep_list[i].path); 363*7c478bd9Sstevel@tonic-gate } 364*7c478bd9Sstevel@tonic-gate /* 365*7c478bd9Sstevel@tonic-gate * If the number of servers is not 1 then resource is 366*7c478bd9Sstevel@tonic-gate * either a failover list or there is an error. In either 367*7c478bd9Sstevel@tonic-gate * case the path can't be determined and curpath is set to 368*7c478bd9Sstevel@tonic-gate * unknown". 369*7c478bd9Sstevel@tonic-gate */ 370*7c478bd9Sstevel@tonic-gate if (server_count == 1) { 371*7c478bd9Sstevel@tonic-gate if (strcmp(rep_list[0].host, "nfs") == 0) { 372*7c478bd9Sstevel@tonic-gate char *path; 373*7c478bd9Sstevel@tonic-gate char *last; 374*7c478bd9Sstevel@tonic-gate path = strdup(rep_list[0].path); 375*7c478bd9Sstevel@tonic-gate if ((path = (char *)strtok_r(path, "//", 376*7c478bd9Sstevel@tonic-gate &last)) != NULL) { 377*7c478bd9Sstevel@tonic-gate strcpy(mrp->nml_curpath, 378*7c478bd9Sstevel@tonic-gate strcat("/", last)); 379*7c478bd9Sstevel@tonic-gate } else { 380*7c478bd9Sstevel@tonic-gate /* 381*7c478bd9Sstevel@tonic-gate * If NULL is returned this is an 382*7c478bd9Sstevel@tonic-gate * invalid path entry. no path can 383*7c478bd9Sstevel@tonic-gate * be determined. 384*7c478bd9Sstevel@tonic-gate */ 385*7c478bd9Sstevel@tonic-gate strcpy(mrp->nml_curpath, "unknown"); 386*7c478bd9Sstevel@tonic-gate } 387*7c478bd9Sstevel@tonic-gate } else { 388*7c478bd9Sstevel@tonic-gate strcpy(mrp->nml_curpath, 389*7c478bd9Sstevel@tonic-gate (strchr(mrp->nml_failoverlist[0], 390*7c478bd9Sstevel@tonic-gate ':') + 1)); 391*7c478bd9Sstevel@tonic-gate } 392*7c478bd9Sstevel@tonic-gate } else { 393*7c478bd9Sstevel@tonic-gate /* 394*7c478bd9Sstevel@tonic-gate * more than one server in the failover list 395*7c478bd9Sstevel@tonic-gate * path can't be determined. 396*7c478bd9Sstevel@tonic-gate */ 397*7c478bd9Sstevel@tonic-gate strcpy(mrp->nml_curpath, "unknown"); 398*7c478bd9Sstevel@tonic-gate } 399*7c478bd9Sstevel@tonic-gate 400*7c478bd9Sstevel@tonic-gate mrp->nml_failovercount = server_count; 401*7c478bd9Sstevel@tonic-gate 402*7c478bd9Sstevel@tonic-gate for (i = 0; i < server_count; i++) { 403*7c478bd9Sstevel@tonic-gate if (rep_list[i].host) { 404*7c478bd9Sstevel@tonic-gate free(rep_list[i].host); 405*7c478bd9Sstevel@tonic-gate } 406*7c478bd9Sstevel@tonic-gate if (rep_list[i].path) { 407*7c478bd9Sstevel@tonic-gate free(rep_list[i].path); 408*7c478bd9Sstevel@tonic-gate } 409*7c478bd9Sstevel@tonic-gate } 410*7c478bd9Sstevel@tonic-gate free(rep_list); 411*7c478bd9Sstevel@tonic-gate 412*7c478bd9Sstevel@tonic-gate if ((mrp->nml_mountp = strdup(fsmnt_list->mountp)) == NULL) { 413*7c478bd9Sstevel@tonic-gate *errp = errno; 414*7c478bd9Sstevel@tonic-gate nfs_free_mntinfo_list(mrp); 415*7c478bd9Sstevel@tonic-gate return (NULL); 416*7c478bd9Sstevel@tonic-gate } 417*7c478bd9Sstevel@tonic-gate if ((mrp->nml_fstype = strdup(fsmnt_list->fstype)) == NULL) { 418*7c478bd9Sstevel@tonic-gate *errp = errno; 419*7c478bd9Sstevel@tonic-gate nfs_free_mntinfo_list(mrp); 420*7c478bd9Sstevel@tonic-gate return (NULL); 421*7c478bd9Sstevel@tonic-gate } 422*7c478bd9Sstevel@tonic-gate if ((mrp->nml_mntopts = strdup(fsmnt_list->mntopts)) == NULL) { 423*7c478bd9Sstevel@tonic-gate *errp = errno; 424*7c478bd9Sstevel@tonic-gate nfs_free_mntinfo_list(mrp); 425*7c478bd9Sstevel@tonic-gate return (NULL); 426*7c478bd9Sstevel@tonic-gate } 427*7c478bd9Sstevel@tonic-gate if ((mrp->nml_time = strdup(fsmnt_list->time)) == NULL) { 428*7c478bd9Sstevel@tonic-gate *errp = errno; 429*7c478bd9Sstevel@tonic-gate nfs_free_mntinfo_list(mrp); 430*7c478bd9Sstevel@tonic-gate return (NULL); 431*7c478bd9Sstevel@tonic-gate } 432*7c478bd9Sstevel@tonic-gate if (fsmnt_list->overlayed) { 433*7c478bd9Sstevel@tonic-gate mrp->nml_overlayed = B_TRUE; 434*7c478bd9Sstevel@tonic-gate } else { 435*7c478bd9Sstevel@tonic-gate mrp->nml_overlayed = B_FALSE; 436*7c478bd9Sstevel@tonic-gate } 437*7c478bd9Sstevel@tonic-gate return (mrp); 438*7c478bd9Sstevel@tonic-gate } /* get_mount_data */ 439*7c478bd9Sstevel@tonic-gate 440*7c478bd9Sstevel@tonic-gate kid_t 441*7c478bd9Sstevel@tonic-gate safe_kstat_read( 442*7c478bd9Sstevel@tonic-gate kstat_ctl_t *libkstat_cookie, 443*7c478bd9Sstevel@tonic-gate kstat_t *ksp, 444*7c478bd9Sstevel@tonic-gate void *data, 445*7c478bd9Sstevel@tonic-gate int *errp) 446*7c478bd9Sstevel@tonic-gate { 447*7c478bd9Sstevel@tonic-gate 448*7c478bd9Sstevel@tonic-gate kid_t kstat_chain_id = kstat_read(libkstat_cookie, ksp, data); 449*7c478bd9Sstevel@tonic-gate 450*7c478bd9Sstevel@tonic-gate if (kstat_chain_id == -1) { 451*7c478bd9Sstevel@tonic-gate *errp = errno; 452*7c478bd9Sstevel@tonic-gate return (-1); 453*7c478bd9Sstevel@tonic-gate } 454*7c478bd9Sstevel@tonic-gate return (kstat_chain_id); 455*7c478bd9Sstevel@tonic-gate } /* safe_kstat_read */ 456*7c478bd9Sstevel@tonic-gate 457*7c478bd9Sstevel@tonic-gate 458*7c478bd9Sstevel@tonic-gate /* 459*7c478bd9Sstevel@tonic-gate * ignore - Checks for the ignore mount option in the mount opts string. 460*7c478bd9Sstevel@tonic-gate * Returns 1 if the ignore option is found and 0 if not. 461*7c478bd9Sstevel@tonic-gate */ 462*7c478bd9Sstevel@tonic-gate static int 463*7c478bd9Sstevel@tonic-gate ignore(char *opts) 464*7c478bd9Sstevel@tonic-gate { 465*7c478bd9Sstevel@tonic-gate char *value; 466*7c478bd9Sstevel@tonic-gate char *s; 467*7c478bd9Sstevel@tonic-gate char *tmp; 468*7c478bd9Sstevel@tonic-gate 469*7c478bd9Sstevel@tonic-gate if (opts == NULL) 470*7c478bd9Sstevel@tonic-gate return (0); 471*7c478bd9Sstevel@tonic-gate s = strdup(opts); 472*7c478bd9Sstevel@tonic-gate if (s == NULL) 473*7c478bd9Sstevel@tonic-gate return (0); 474*7c478bd9Sstevel@tonic-gate 475*7c478bd9Sstevel@tonic-gate tmp = s; 476*7c478bd9Sstevel@tonic-gate 477*7c478bd9Sstevel@tonic-gate while (*s != '\0') { 478*7c478bd9Sstevel@tonic-gate if (getsubopt(&s, mntopts, &value) == IGNORE) { 479*7c478bd9Sstevel@tonic-gate free(tmp); 480*7c478bd9Sstevel@tonic-gate return (1); 481*7c478bd9Sstevel@tonic-gate } 482*7c478bd9Sstevel@tonic-gate } 483*7c478bd9Sstevel@tonic-gate free(tmp); 484*7c478bd9Sstevel@tonic-gate return (0); 485*7c478bd9Sstevel@tonic-gate } /* ignore */ 486