/* * Method: nfssec_get_default_secmode * * Description: Retrieves the default security mode for NFS. * * Parameters: * - int *errp - the error indicator. This will be set to a non-zero * value upon error. * * Returns: * - char * - the NFS security mode name. * - NULL if an error occurred. * * Note: Caller must free the space allocated for the return value. */ char * nfssec_get_default_secmode(int *errp) { seconfig_t secp, defsecp; char *ret_val; int err = 0; *errp = 0; err = nfs_getseconfig_default(&secp); if (err != 0) { *errp = err; return (NULL); } err = nfs_getseconfig_bynumber(secp.sc_nfsnum, &defsecp); if (err != 0) { *errp = err; return (NULL); } ret_val = strdup(defsecp.sc_name); if (ret_val == NULL) { *errp = ENOMEM; return (NULL); } return (ret_val); } /* nfssec_get_default_secmode */
/* * Print the mount table info */ static void mi_print(void) { FILE *mt; struct extmnttab m; struct myrec *list, *mrp, *pmrp; char *flavor; int ignored = 0; seconfig_t nfs_sec; kstat_t *ksp; struct mntinfo_kstat mik; int transport_flag = 0; int path_count; int found; char *timer_name[] = { "Lookups", "Reads", "Writes", "All" }; mt = fopen(MNTTAB, "r"); if (mt == NULL) { perror(MNTTAB); exit(0); } list = NULL; resetmnttab(mt); while (getextmntent(mt, &m, sizeof (struct extmnttab)) == 0) { /* ignore non "nfs" and save the "ignore" entries */ if (strcmp(m.mnt_fstype, MNTTYPE_NFS) != 0) continue; /* * Check to see here if user gave a path(s) to * only show the mount point they wanted * Iterate through the list of paths the user gave and see * if any of them match our current nfs mount */ if (path[0] != NULL) { found = 0; for (path_count = 0; path[path_count] != NULL; path_count++) { if (strcmp(path[path_count], m.mnt_mountp) == 0) { found = 1; break; } } if (!found) continue; } if ((mrp = malloc(sizeof (struct myrec))) == 0) { fprintf(stderr, "nfsstat: not enough memory\n"); exit(1); } mrp->my_fsid = makedev(m.mnt_major, m.mnt_minor); if (ignore(m.mnt_mntopts)) { /* * ignored entries cannot be ignored for this * option. We have to display the info for this * nfs mount. The ignore is an indication * that the actual mount point is different and * something is in between the nfs mount. * So save the mount point now */ if ((mrp->ig_path = malloc( strlen(m.mnt_mountp) + 1)) == 0) { fprintf(stderr, "nfsstat: not enough memory\n"); exit(1); } (void) strcpy(mrp->ig_path, m.mnt_mountp); ignored++; } else { mrp->ig_path = 0; (void) strcpy(mrp->my_dir, m.mnt_mountp); } if ((mrp->my_path = strdup(m.mnt_special)) == NULL) { fprintf(stderr, "nfsstat: not enough memory\n"); exit(1); } mrp->next = list; list = mrp; } /* * If something got ignored, go to the beginning of the mnttab * and look for the cachefs entries since they are the one * causing this. The mount point saved for the ignored entries * is matched against the special to get the actual mount point. * We are interested in the acutal mount point so that the output * look nice too. */ if (ignored) { rewind(mt); resetmnttab(mt); while (getextmntent(mt, &m, sizeof (struct extmnttab)) == 0) { /* ignore non "cachefs" */ if (strcmp(m.mnt_fstype, MNTTYPE_CACHEFS) != 0) continue; for (mrp = list; mrp; mrp = mrp->next) { if (mrp->ig_path == 0) continue; if (strcmp(mrp->ig_path, m.mnt_special) == 0) { mrp->ig_path = 0; (void) strcpy(mrp->my_dir, m.mnt_mountp); } } } /* * Now ignored entries which do not have * the my_dir initialized are really ignored; This never * happens unless the mnttab is corrupted. */ for (pmrp = 0, mrp = list; mrp; mrp = mrp->next) { if (mrp->ig_path == 0) pmrp = mrp; else if (pmrp) pmrp->next = mrp->next; else list = mrp->next; } } (void) fclose(mt); for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) { int i; if (ksp->ks_type != KSTAT_TYPE_RAW) continue; if (strcmp(ksp->ks_module, "nfs") != 0) continue; if (strcmp(ksp->ks_name, "mntinfo") != 0) continue; for (mrp = list; mrp; mrp = mrp->next) { if ((mrp->my_fsid & MAXMIN) == ksp->ks_instance) break; } if (mrp == 0) continue; if (safe_kstat_read(kc, ksp, &mik) == -1) continue; printf("%s from %s\n", mrp->my_dir, mrp->my_path); /* * for printing rdma transport and provider string. * This way we avoid modifying the kernel mntinfo_kstat * struct for protofmly. */ if (strcmp(mik.mik_proto, "ibtf") == 0) { printf(" Flags: vers=%u,proto=rdma", mik.mik_vers); transport_flag = 1; } else { printf(" Flags: vers=%u,proto=%s", mik.mik_vers, mik.mik_proto); transport_flag = 0; } /* * get the secmode name from /etc/nfssec.conf. */ if (!nfs_getseconfig_bynumber(mik.mik_secmod, &nfs_sec)) { flavor = nfs_sec.sc_name; } else flavor = NULL; if (flavor != NULL) printf(",sec=%s", flavor); else printf(",sec#=%d", mik.mik_secmod); printf(",%s", (mik.mik_flags & MI_HARD) ? "hard" : "soft"); if (mik.mik_flags & MI_PRINTED) printf(",printed"); printf(",%s", (mik.mik_flags & MI_INT) ? "intr" : "nointr"); if (mik.mik_flags & MI_DOWN) printf(",down"); if (mik.mik_flags & MI_NOAC) printf(",noac"); if (mik.mik_flags & MI_NOCTO) printf(",nocto"); if (mik.mik_flags & MI_DYNAMIC) printf(",dynamic"); if (mik.mik_flags & MI_LLOCK) printf(",llock"); if (mik.mik_flags & MI_GRPID) printf(",grpid"); if (mik.mik_flags & MI_RPCTIMESYNC) printf(",rpctimesync"); if (mik.mik_flags & MI_LINK) printf(",link"); if (mik.mik_flags & MI_SYMLINK) printf(",symlink"); if (mik.mik_vers < NFS_V4 && mik.mik_flags & MI_READDIRONLY) printf(",readdironly"); if (mik.mik_flags & MI_ACL) printf(",acl"); if (mik.mik_vers >= NFS_V4) { if (mik.mik_flags & MI4_MIRRORMOUNT) printf(",mirrormount"); } printf(",rsize=%d,wsize=%d,retrans=%d,timeo=%d", mik.mik_curread, mik.mik_curwrite, mik.mik_retrans, mik.mik_timeo); printf("\n"); printf(" Attr cache: acregmin=%d,acregmax=%d" ",acdirmin=%d,acdirmax=%d\n", mik.mik_acregmin, mik.mik_acregmax, mik.mik_acdirmin, mik.mik_acdirmax); if (transport_flag) { printf(" Transport: proto=rdma, plugin=%s\n", mik.mik_proto); } #define srtt_to_ms(x) x, (x * 2 + x / 2) #define dev_to_ms(x) x, (x * 5) for (i = 0; i < NFS_CALLTYPES + 1; i++) { int j; j = (i == NFS_CALLTYPES ? i - 1 : i); if (mik.mik_timers[j].srtt || mik.mik_timers[j].rtxcur) { printf(" %s: srtt=%d (%dms), " "dev=%d (%dms), cur=%u (%ums)\n", timer_name[i], srtt_to_ms(mik.mik_timers[i].srtt), dev_to_ms(mik.mik_timers[i].deviate), mik.mik_timers[i].rtxcur, mik.mik_timers[i].rtxcur * 20); } } if (strchr(mrp->my_path, ',')) printf( " Failover: noresponse=%d,failover=%d," "remap=%d,currserver=%s\n", mik.mik_noresponse, mik.mik_failover, mik.mik_remap, mik.mik_curserver); printf("\n"); } }