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 /*
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #pragma ident "%Z%%M% %I% %E% SMI"
28
29 #include <fs/fs_subr.h>
30
31 #include <sys/errno.h>
32 #include <sys/file.h>
33 #include <sys/kmem.h>
34 #include <sys/kobj.h>
35 #include <sys/cmn_err.h>
36 #include <sys/stat.h>
37 #include <sys/systm.h>
38 #include <sys/sysmacros.h>
39 #include <sys/atomic.h>
40 #include <sys/vfs.h>
41 #include <sys/vfs_opreg.h>
42
43 #include <sharefs/sharefs.h>
44
45 /*
46 * sharefs_snap_create: create a large character buffer with
47 * the shares enumerated.
48 */
236 ((gfs_file_t *)vp->v_data)->gfs_ino = SHAREFS_INO_FILE;
237
238 /*
239 * Hold the parent!
240 */
241 VFS_HOLD(ovp->v_vfsp);
242
243 VN_SET_VFS_TYPE_DEV(vp, ovp->v_vfsp, VREG, 0);
244
245 vp->v_flag |= VROOT | VNOCACHE | VNOMAP | VNOSWAP | VNOMOUNT;
246
247 *vpp = vp;
248 VN_RELE(ovp);
249
250 sft = VTOSH(vp);
251
252 /*
253 * No need for the lock, no other thread can be accessing
254 * this data structure.
255 */
256 atomic_add_32(&sft->sharefs_refs, 1);
257 sft->sharefs_real_vp = 0;
258
259 /*
260 * Since the sharetab could easily change on us whilst we
261 * are dumping an extremely huge sharetab, we make a copy
262 * of it here and use it to dump instead.
263 */
264 error = sharefs_snap_create(sft);
265
266 return (error);
267 }
268
269 /* ARGSUSED */
270 int
271 sharefs_close(vnode_t *vp, int flag, int count,
272 offset_t off, cred_t *cr, caller_context_t *ct)
273 {
274 shnode_t *sft = VTOSH(vp);
275
276 if (count > 1)
277 return (0);
278
279 rw_enter(&sharefs_lock, RW_WRITER);
280 if (vp->v_count == 1) {
281 if (sft->sharefs_snap != NULL) {
282 kmem_free(sft->sharefs_snap, sft->sharefs_size + 1);
283 sft->sharefs_size = 0;
284 sft->sharefs_snap = NULL;
285 sft->sharefs_generation = 0;
286 }
287 }
288 atomic_add_32(&sft->sharefs_refs, -1);
289 rw_exit(&sharefs_lock);
290
291 return (0);
292 }
293
294 /* ARGSUSED */
295 static int
296 sharefs_read(vnode_t *vp, uio_t *uio, int ioflag, cred_t *cr,
297 caller_context_t *ct)
298 {
299 shnode_t *sft = VTOSH(vp);
300 off_t off = uio->uio_offset;
301 size_t len = uio->uio_resid;
302 int error = 0;
303
304 rw_enter(&sharefs_lock, RW_READER);
305
306 /*
307 * First check to see if we need to grab a new snapshot.
308 */
|
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 /*
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 #include <fs/fs_subr.h>
28
29 #include <sys/errno.h>
30 #include <sys/file.h>
31 #include <sys/kmem.h>
32 #include <sys/kobj.h>
33 #include <sys/cmn_err.h>
34 #include <sys/stat.h>
35 #include <sys/systm.h>
36 #include <sys/sysmacros.h>
37 #include <sys/atomic.h>
38 #include <sys/vfs.h>
39 #include <sys/vfs_opreg.h>
40
41 #include <sharefs/sharefs.h>
42
43 /*
44 * sharefs_snap_create: create a large character buffer with
45 * the shares enumerated.
46 */
234 ((gfs_file_t *)vp->v_data)->gfs_ino = SHAREFS_INO_FILE;
235
236 /*
237 * Hold the parent!
238 */
239 VFS_HOLD(ovp->v_vfsp);
240
241 VN_SET_VFS_TYPE_DEV(vp, ovp->v_vfsp, VREG, 0);
242
243 vp->v_flag |= VROOT | VNOCACHE | VNOMAP | VNOSWAP | VNOMOUNT;
244
245 *vpp = vp;
246 VN_RELE(ovp);
247
248 sft = VTOSH(vp);
249
250 /*
251 * No need for the lock, no other thread can be accessing
252 * this data structure.
253 */
254 atomic_inc_32(&sft->sharefs_refs);
255 sft->sharefs_real_vp = 0;
256
257 /*
258 * Since the sharetab could easily change on us whilst we
259 * are dumping an extremely huge sharetab, we make a copy
260 * of it here and use it to dump instead.
261 */
262 error = sharefs_snap_create(sft);
263
264 return (error);
265 }
266
267 /* ARGSUSED */
268 int
269 sharefs_close(vnode_t *vp, int flag, int count,
270 offset_t off, cred_t *cr, caller_context_t *ct)
271 {
272 shnode_t *sft = VTOSH(vp);
273
274 if (count > 1)
275 return (0);
276
277 rw_enter(&sharefs_lock, RW_WRITER);
278 if (vp->v_count == 1) {
279 if (sft->sharefs_snap != NULL) {
280 kmem_free(sft->sharefs_snap, sft->sharefs_size + 1);
281 sft->sharefs_size = 0;
282 sft->sharefs_snap = NULL;
283 sft->sharefs_generation = 0;
284 }
285 }
286 atomic_dec_32(&sft->sharefs_refs);
287 rw_exit(&sharefs_lock);
288
289 return (0);
290 }
291
292 /* ARGSUSED */
293 static int
294 sharefs_read(vnode_t *vp, uio_t *uio, int ioflag, cred_t *cr,
295 caller_context_t *ct)
296 {
297 shnode_t *sft = VTOSH(vp);
298 off_t off = uio->uio_offset;
299 size_t len = uio->uio_resid;
300 int error = 0;
301
302 rw_enter(&sharefs_lock, RW_READER);
303
304 /*
305 * First check to see if we need to grab a new snapshot.
306 */
|