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 2010 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 /*
  27  *      Copyright (c) 1983,1984,1985,1986,1987,1988,1989 AT&T.
  28  *      All rights reserved.
  29  */
  30 
  31 /*
  32  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
  33  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  34  */
  35 
  36 #include <sys/param.h>
  37 #include <sys/types.h>
  38 #include <sys/systm.h>
  39 #include <sys/cred.h>
  40 #include <sys/time.h>
  41 #include <sys/vnode.h>
  42 #include <sys/vfs.h>
  43 #include <sys/vfs_opreg.h>
  44 #include <sys/file.h>
  45 #include <sys/filio.h>
  46 #include <sys/uio.h>
  47 #include <sys/buf.h>
  48 #include <sys/mman.h>
  49 #include <sys/pathname.h>
  50 #include <sys/dirent.h>
  51 #include <sys/debug.h>
  52 #include <sys/vmsystm.h>
 
 
3336         } else {
3337                 nfs3_cache_wcc_data(odvp, &res.resfail.fromdir_wcc, t, cr);
3338                 if (ndvp != odvp) {
3339                         nfs3_cache_wcc_data(ndvp, &res.resfail.todir_wcc, t,
3340                             cr);
3341                 }
3342                 /*
3343                  * System V defines rename to return EEXIST, not
3344                  * ENOTEMPTY if the target directory is not empty.
3345                  * Over the wire, the error is NFSERR_ENOTEMPTY
3346                  * which geterrno maps to ENOTEMPTY.
3347                  */
3348                 if (error == ENOTEMPTY)
3349                         error = EEXIST;
3350         }
3351 
3352         if (error == 0) {
3353                 if (nvp)
3354                         vnevent_rename_dest(nvp, ndvp, nnm, ct);
3355 
3356                 if (odvp != ndvp)
3357                         vnevent_rename_dest_dir(ndvp, ct);
3358                 ASSERT(ovp != NULL);
3359                 vnevent_rename_src(ovp, odvp, onm, ct);
3360         }
3361 
3362         if (nvp) {
3363                 VN_RELE(nvp);
3364         }
3365         VN_RELE(ovp);
3366 
3367         nfs_rw_exit(&odrp->r_rwlock);
3368         nfs_rw_exit(&ndrp->r_rwlock);
3369 
3370         return (error);
3371 }
3372 
3373 /* ARGSUSED */
3374 static int
3375 nfs3_mkdir(vnode_t *dvp, char *nm, struct vattr *va, vnode_t **vpp, cred_t *cr,
3376         caller_context_t *ct, int flags, vsecattr_t *vsecp)
3377 {
3378         int error;
3379         MKDIR3args args;
 
5506 
5507         error = convoff(vp, bfp, 0, offset);
5508         if (!error) {
5509                 ASSERT(bfp->l_start >= 0);
5510                 if (bfp->l_len == 0) {
5511                         struct vattr va;
5512 
5513                         /*
5514                          * ftruncate should not change the ctime and
5515                          * mtime if we truncate the file to its
5516                          * previous size.
5517                          */
5518                         va.va_mask = AT_SIZE;
5519                         error = nfs3getattr(vp, &va, cr);
5520                         if (error || va.va_size == bfp->l_start)
5521                                 return (error);
5522                         va.va_mask = AT_SIZE;
5523                         va.va_size = bfp->l_start;
5524                         error = nfs3setattr(vp, &va, 0, cr);
5525 
5526                         if (error == 0 && bfp->l_start == 0)
5527                                 vnevent_truncate(vp, ct);
5528                 } else
5529                         error = EINVAL;
5530         }
5531 
5532         return (error);
5533 }
5534 
5535 /* ARGSUSED */
5536 static int
5537 nfs3_realvp(vnode_t *vp, vnode_t **vpp, caller_context_t *ct)
5538 {
5539 
5540         return (EINVAL);
5541 }
5542 
5543 /*
5544  * Setup and add an address space callback to do the work of the delmap call.
5545  * The callback will (and must be) deleted in the actual callback function.
5546  *
5547  * This is done in order to take care of the problem that we have with holding
 
 | 
 
 
  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 2010 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 /*
  27  *      Copyright (c) 1983,1984,1985,1986,1987,1988,1989 AT&T.
  28  *      All rights reserved.
  29  */
  30 
  31 /*
  32  * Copyright (c) 2014, Joyent, Inc. All rights reserved.
  33  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
  34  */
  35 
  36 #include <sys/param.h>
  37 #include <sys/types.h>
  38 #include <sys/systm.h>
  39 #include <sys/cred.h>
  40 #include <sys/time.h>
  41 #include <sys/vnode.h>
  42 #include <sys/vfs.h>
  43 #include <sys/vfs_opreg.h>
  44 #include <sys/file.h>
  45 #include <sys/filio.h>
  46 #include <sys/uio.h>
  47 #include <sys/buf.h>
  48 #include <sys/mman.h>
  49 #include <sys/pathname.h>
  50 #include <sys/dirent.h>
  51 #include <sys/debug.h>
  52 #include <sys/vmsystm.h>
 
 
3336         } else {
3337                 nfs3_cache_wcc_data(odvp, &res.resfail.fromdir_wcc, t, cr);
3338                 if (ndvp != odvp) {
3339                         nfs3_cache_wcc_data(ndvp, &res.resfail.todir_wcc, t,
3340                             cr);
3341                 }
3342                 /*
3343                  * System V defines rename to return EEXIST, not
3344                  * ENOTEMPTY if the target directory is not empty.
3345                  * Over the wire, the error is NFSERR_ENOTEMPTY
3346                  * which geterrno maps to ENOTEMPTY.
3347                  */
3348                 if (error == ENOTEMPTY)
3349                         error = EEXIST;
3350         }
3351 
3352         if (error == 0) {
3353                 if (nvp)
3354                         vnevent_rename_dest(nvp, ndvp, nnm, ct);
3355 
3356                 ASSERT(ovp != NULL);
3357                 vnevent_rename_src(ovp, odvp, onm, ct);
3358                 vnevent_rename_dest_dir(ndvp, ovp, nnm, ct);
3359         }
3360 
3361         if (nvp) {
3362                 VN_RELE(nvp);
3363         }
3364         VN_RELE(ovp);
3365 
3366         nfs_rw_exit(&odrp->r_rwlock);
3367         nfs_rw_exit(&ndrp->r_rwlock);
3368 
3369         return (error);
3370 }
3371 
3372 /* ARGSUSED */
3373 static int
3374 nfs3_mkdir(vnode_t *dvp, char *nm, struct vattr *va, vnode_t **vpp, cred_t *cr,
3375         caller_context_t *ct, int flags, vsecattr_t *vsecp)
3376 {
3377         int error;
3378         MKDIR3args args;
 
5505 
5506         error = convoff(vp, bfp, 0, offset);
5507         if (!error) {
5508                 ASSERT(bfp->l_start >= 0);
5509                 if (bfp->l_len == 0) {
5510                         struct vattr va;
5511 
5512                         /*
5513                          * ftruncate should not change the ctime and
5514                          * mtime if we truncate the file to its
5515                          * previous size.
5516                          */
5517                         va.va_mask = AT_SIZE;
5518                         error = nfs3getattr(vp, &va, cr);
5519                         if (error || va.va_size == bfp->l_start)
5520                                 return (error);
5521                         va.va_mask = AT_SIZE;
5522                         va.va_size = bfp->l_start;
5523                         error = nfs3setattr(vp, &va, 0, cr);
5524 
5525                         if (error == 0) {
5526                                 if (bfp->l_start == 0) {
5527                                         vnevent_truncate(vp, ct);
5528                                 } else {
5529                                         vnevent_resize(vp, ct);
5530                                 }
5531                         }
5532                 } else
5533                         error = EINVAL;
5534         }
5535 
5536         return (error);
5537 }
5538 
5539 /* ARGSUSED */
5540 static int
5541 nfs3_realvp(vnode_t *vp, vnode_t **vpp, caller_context_t *ct)
5542 {
5543 
5544         return (EINVAL);
5545 }
5546 
5547 /*
5548  * Setup and add an address space callback to do the work of the delmap call.
5549  * The callback will (and must be) deleted in the actual callback function.
5550  *
5551  * This is done in order to take care of the problem that we have with holding
 
 |