140
141 static smbnode_t *
142 sn_hashfind(smbmntinfo_t *, const char *, int, avl_index_t *);
143
144 static smbnode_t *
145 make_smbnode(smbmntinfo_t *, const char *, int, int *);
146
147 /*
148 * Free the resources associated with an smbnode.
149 * Note: This is different from smbfs_inactive
150 *
151 * NFS: nfs_subr.c:rinactive
152 */
153 static void
154 sn_inactive(smbnode_t *np)
155 {
156 vsecattr_t ovsa;
157 cred_t *oldcr;
158 char *orpath;
159 int orplen;
160
161 /*
162 * Flush and invalidate all pages (todo)
163 * Free any held credentials and caches...
164 * etc. (See NFS code)
165 */
166 mutex_enter(&np->r_statelock);
167
168 ovsa = np->r_secattr;
169 np->r_secattr = smbfs_vsa0;
170 np->r_sectime = 0;
171
172 oldcr = np->r_cred;
173 np->r_cred = NULL;
174
175 orpath = np->n_rpath;
176 orplen = np->n_rplen;
177 np->n_rpath = NULL;
178 np->n_rplen = 0;
179
180 mutex_exit(&np->r_statelock);
181
182 if (ovsa.vsa_aclentp != NULL)
183 kmem_free(ovsa.vsa_aclentp, ovsa.vsa_aclentsz);
184
185 if (oldcr != NULL)
186 crfree(oldcr);
187
188 if (orpath != NULL)
189 kmem_free(orpath, orplen + 1);
190 }
191
192 /*
193 * Find and optionally create an smbnode for the passed
194 * mountinfo, directory, separator, and name. If the
195 * desired smbnode already exists, return a reference.
196 * If the file attributes pointer is non-null, the node
197 * is created if necessary and linked into the AVL tree.
198 *
199 * Callers that need a node created but don't have the
200 * real attributes pass smbfs_fattr0 to force creation.
201 *
1023 ASSERT(np->r_count == 0);
1024 ASSERT(np->r_mapcnt == 0);
1025 ASSERT(np->r_secattr.vsa_aclentp == NULL);
1026 ASSERT(np->r_cred == NULL);
1027 ASSERT(np->n_rpath == NULL);
1028 ASSERT(!(np->r_flags & RHASHED));
1029 ASSERT(np->r_freef == NULL && np->r_freeb == NULL);
1030 atomic_add_long((ulong_t *)&smbnodenew, -1);
1031 vn_invalid(vp);
1032 vn_free(vp);
1033 kmem_cache_free(smbnode_cache, np);
1034 VFS_RELE(vfsp);
1035 }
1036
1037 /*
1038 * Flush all vnodes in this (or every) vfs.
1039 * Used by nfs_sync and by nfs_unmount.
1040 */
1041 /*ARGSUSED*/
1042 void
1043 smbfs_rflush(struct vfs *vfsp, cred_t *cr)
1044 {
1045 /* Todo: mmap support. */
1046 }
1047
1048 /* access cache */
1049 /* client handles */
1050
1051 /*
1052 * initialize resources that are used by smbfs_subr.c
1053 * this is called from the _init() routine (by the way of smbfs_clntinit())
1054 *
1055 * NFS: nfs_subr.c:nfs_subrinit
1056 */
1057 int
1058 smbfs_subrinit(void)
1059 {
1060 ulong_t nsmbnode_max;
1061
1062 /*
1063 * Allocate and initialize the smbnode cache
1064 */
1065 if (nsmbnode <= 0)
|
140
141 static smbnode_t *
142 sn_hashfind(smbmntinfo_t *, const char *, int, avl_index_t *);
143
144 static smbnode_t *
145 make_smbnode(smbmntinfo_t *, const char *, int, int *);
146
147 /*
148 * Free the resources associated with an smbnode.
149 * Note: This is different from smbfs_inactive
150 *
151 * NFS: nfs_subr.c:rinactive
152 */
153 static void
154 sn_inactive(smbnode_t *np)
155 {
156 vsecattr_t ovsa;
157 cred_t *oldcr;
158 char *orpath;
159 int orplen;
160 vnode_t *vp;
161
162 /*
163 * Flush and invalidate all pages
164 * Free any held credentials and caches...
165 * etc. (See NFS code)
166 */
167 mutex_enter(&np->r_statelock);
168
169 ovsa = np->r_secattr;
170 np->r_secattr = smbfs_vsa0;
171 np->r_sectime = 0;
172
173 oldcr = np->r_cred;
174 np->r_cred = NULL;
175
176 orpath = np->n_rpath;
177 orplen = np->n_rplen;
178 np->n_rpath = NULL;
179 np->n_rplen = 0;
180
181 mutex_exit(&np->r_statelock);
182
183 vp = SMBTOV(np);
184 if (vn_has_cached_data(vp)) {
185 smbfs_invalidate_pages(vp, (u_offset_t) 0, oldcr);
186 }
187
188 if (ovsa.vsa_aclentp != NULL)
189 kmem_free(ovsa.vsa_aclentp, ovsa.vsa_aclentsz);
190
191 if (oldcr != NULL)
192 crfree(oldcr);
193
194 if (orpath != NULL)
195 kmem_free(orpath, orplen + 1);
196 }
197
198 /*
199 * Find and optionally create an smbnode for the passed
200 * mountinfo, directory, separator, and name. If the
201 * desired smbnode already exists, return a reference.
202 * If the file attributes pointer is non-null, the node
203 * is created if necessary and linked into the AVL tree.
204 *
205 * Callers that need a node created but don't have the
206 * real attributes pass smbfs_fattr0 to force creation.
207 *
1029 ASSERT(np->r_count == 0);
1030 ASSERT(np->r_mapcnt == 0);
1031 ASSERT(np->r_secattr.vsa_aclentp == NULL);
1032 ASSERT(np->r_cred == NULL);
1033 ASSERT(np->n_rpath == NULL);
1034 ASSERT(!(np->r_flags & RHASHED));
1035 ASSERT(np->r_freef == NULL && np->r_freeb == NULL);
1036 atomic_add_long((ulong_t *)&smbnodenew, -1);
1037 vn_invalid(vp);
1038 vn_free(vp);
1039 kmem_cache_free(smbnode_cache, np);
1040 VFS_RELE(vfsp);
1041 }
1042
1043 /*
1044 * Flush all vnodes in this (or every) vfs.
1045 * Used by nfs_sync and by nfs_unmount.
1046 */
1047 /*ARGSUSED*/
1048 void
1049 smbfs_rflush(struct vfs *vfsp, cred_t *cr) {
1050
1051 smbmntinfo_t *mi;
1052 smbnode_t *np;
1053 vnode_t *vp;
1054
1055 long num, cnt;
1056
1057 vnode_t **vplist;
1058
1059 mi = VFTOSMI(vfsp);
1060
1061 cnt = 0;
1062 num = mi->smi_hash_avl.avl_numnodes;
1063 vplist = kmem_alloc(num * sizeof (vnode_t*), KM_SLEEP);
1064
1065 rw_enter(&mi->smi_hash_lk, RW_READER);
1066 for (np = avl_first(&mi->smi_hash_avl); np != NULL;
1067 np = avl_walk(&mi->smi_hash_avl, np, AVL_AFTER)) {
1068 vp = SMBTOV(np);
1069 if (vn_is_readonly(vp))
1070 continue;
1071
1072 if (vn_has_cached_data(vp) && (np->r_flags & RDIRTY || np->r_mapcnt > 0)) {
1073 VN_HOLD(vp);
1074 vplist[cnt++] = vp;
1075 if (cnt == num)
1076 break;
1077 }
1078 }
1079 rw_exit(&mi->smi_hash_lk);
1080
1081 while (cnt-- > 0) {
1082 vp = vplist[cnt];
1083 (void) VOP_PUTPAGE(vp, 0, 0, 0, cr, NULL);
1084 VN_RELE(vp);
1085 }
1086
1087 kmem_free(vplist, num * sizeof (vnode_t*));
1088 }
1089
1090 /* access cache */
1091 /* client handles */
1092
1093 /*
1094 * initialize resources that are used by smbfs_subr.c
1095 * this is called from the _init() routine (by the way of smbfs_clntinit())
1096 *
1097 * NFS: nfs_subr.c:nfs_subrinit
1098 */
1099 int
1100 smbfs_subrinit(void)
1101 {
1102 ulong_t nsmbnode_max;
1103
1104 /*
1105 * Allocate and initialize the smbnode cache
1106 */
1107 if (nsmbnode <= 0)
|