FreeBSD/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_replay.c
/*
 * Replay file create with optional ACL, xvattr information as well
 * as option FUID information.
 */
Replay file create with optional ACL, xvattr information as well
as option FUID information.
Replay file create with optional ACL xvattr information as well as option FUID information .
static int
zfs_replay_create_acl(zfsvfs_t *zfsvfs,
    lr_acl_create_t *lracl, boolean_t byteswap)
{
	char *name = NULL;		
	lr_create_t *lr = (lr_create_t *)lracl;
	znode_t *dzp;
	vnode_t *vp = NULL;
	xvattr_t xva;
	int vflg = 0;
	vsecattr_t vsec = { 0 };
	lr_attr_t *lrattr;
	void *aclstart;
	void *fuidstart;
	size_t xvatlen = 0;
	uint64_t txtype;
	int error;
	txtype = (lr->lr_common.lrc_txtype & ~TX_CI);
	if (byteswap) {
		byteswap_uint64_array(lracl, sizeof (*lracl));
		if (txtype == TX_CREATE_ACL_ATTR ||
		    txtype == TX_MKDIR_ACL_ATTR) {
			lrattr = (lr_attr_t *)(caddr_t)(lracl + 1);
			zfs_replay_swap_attrs(lrattr);
			xvatlen = ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
		}
		aclstart = (caddr_t)(lracl + 1) + xvatlen;
		zfs_ace_byteswap(aclstart, lracl->lr_acl_bytes, B_FALSE);
		if (lracl->lr_fuidcnt) {
			byteswap_uint64_array((caddr_t)aclstart +
			    ZIL_ACE_LENGTH(lracl->lr_acl_bytes),
			    lracl->lr_fuidcnt * sizeof (uint64_t));
		}
	}
	if ((error = zfs_zget(zfsvfs, lr->lr_doid, &dzp)) != 0)
		return (error);
	xva_init(&xva);
	zfs_init_vattr(&xva.xva_vattr, AT_TYPE | AT_MODE | AT_UID | AT_GID,
	    lr->lr_mode, lr->lr_uid, lr->lr_gid, lr->lr_rdev, lr->lr_foid);
	ZFS_TIME_DECODE(&xva.xva_vattr.va_ctime, lr->lr_crtime);
	xva.xva_vattr.va_nblocks = lr->lr_gen;
	error = dmu_object_info(zfsvfs->z_os, lr->lr_foid, NULL);
	if (error != ENOENT)
		goto bail;
	if (lr->lr_common.lrc_txtype & TX_CI)
		vflg |= FIGNORECASE;
	switch (txtype) {
	case TX_CREATE_ACL:
		aclstart = (caddr_t)(lracl + 1);
		fuidstart = (caddr_t)aclstart +
		    ZIL_ACE_LENGTH(lracl->lr_acl_bytes);
		zfsvfs->z_fuid_replay = zfs_replay_fuids(fuidstart,
		    (void *)&name, lracl->lr_fuidcnt, lracl->lr_domcnt,
		    lr->lr_uid, lr->lr_gid);
	case TX_CREATE_ACL_ATTR:
		if (name == NULL) {
			lrattr = (lr_attr_t *)(caddr_t)(lracl + 1);
			xvatlen = ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
			xva.xva_vattr.va_mask |= AT_XVATTR;
			zfs_replay_xvattr(lrattr, &xva);
		}
		vsec.vsa_mask = VSA_ACE | VSA_ACE_ACLFLAGS;
		vsec.vsa_aclentp = (caddr_t)(lracl + 1) + xvatlen;
		vsec.vsa_aclcnt = lracl->lr_aclcnt;
		vsec.vsa_aclentsz = lracl->lr_acl_bytes;
		vsec.vsa_aclflags = lracl->lr_acl_flags;
		if (zfsvfs->z_fuid_replay == NULL) {
			fuidstart = (caddr_t)(lracl + 1) + xvatlen +
			    ZIL_ACE_LENGTH(lracl->lr_acl_bytes);
			zfsvfs->z_fuid_replay =
			    zfs_replay_fuids(fuidstart,
			    (void *)&name, lracl->lr_fuidcnt, lracl->lr_domcnt,
			    lr->lr_uid, lr->lr_gid);
		}
#ifdef TODO
		error = VOP_CREATE(ZTOV(dzp), name, &xva.xva_vattr,
		    0, 0, &vp, kcred, vflg, NULL, &vsec);
#else
		panic("%s:%u: unsupported condition", __func__, __LINE__);
#endif
		break;
	case TX_MKDIR_ACL:
		aclstart = (caddr_t)(lracl + 1);
		fuidstart = (caddr_t)aclstart +
		    ZIL_ACE_LENGTH(lracl->lr_acl_bytes);
		zfsvfs->z_fuid_replay = zfs_replay_fuids(fuidstart,
		    (void *)&name, lracl->lr_fuidcnt, lracl->lr_domcnt,
		    lr->lr_uid, lr->lr_gid);
	case TX_MKDIR_ACL_ATTR:
		if (name == NULL) {
			lrattr = (lr_attr_t *)(caddr_t)(lracl + 1);
			xvatlen = ZIL_XVAT_SIZE(lrattr->lr_attr_masksize);
			zfs_replay_xvattr(lrattr, &xva);
		}
		vsec.vsa_mask = VSA_ACE | VSA_ACE_ACLFLAGS;
		vsec.vsa_aclentp = (caddr_t)(lracl + 1) + xvatlen;
		vsec.vsa_aclcnt = lracl->lr_aclcnt;
		vsec.vsa_aclentsz = lracl->lr_acl_bytes;
		vsec.vsa_aclflags = lracl->lr_acl_flags;
		if (zfsvfs->z_fuid_replay == NULL) {
			fuidstart = (caddr_t)(lracl + 1) + xvatlen +
			    ZIL_ACE_LENGTH(lracl->lr_acl_bytes);
			zfsvfs->z_fuid_replay =
			    zfs_replay_fuids(fuidstart,
			    (void *)&name, lracl->lr_fuidcnt, lracl->lr_domcnt,
			    lr->lr_uid, lr->lr_gid);
		}
#ifdef TODO
		error = VOP_MKDIR(ZTOV(dzp), name, &xva.xva_vattr,
		    &vp, kcred, NULL, vflg, &vsec);
#else
		panic("%s:%u: unsupported condition", __func__, __LINE__);
#endif
		break;
	default:
		error = SET_ERROR(ENOTSUP);
	}
bail:
	if (error == 0 && vp != NULL)
		VN_RELE(vp);
	VN_RELE(ZTOV(dzp));
	if (zfsvfs->z_fuid_replay)
		zfs_fuid_info_free(zfsvfs->z_fuid_replay);
	zfsvfs->z_fuid_replay = NULL;
	return (error);
}
static int zfs_replay_create_acl ( zfsvfs_t * zfsvfs , lr_acl_create_t * lracl , boolean_t byteswap ) { char * name = NULL ; lr_create_t * lr = ( lr_create_t * ) lracl ; znode_t * dzp ; vnode_t * vp = NULL ; xvattr_t xva ; int vflg = 0 ; vsecattr_t vsec = { 0 } ; lr_attr_t * lrattr ; void * aclstart ; void * fuidstart ; size_t xvatlen = 0 ; uint64_t txtype ; int error ; txtype = ( lr -> lr_common . lrc_txtype & ~ TX_CI ) ; if ( byteswap ) { byteswap_uint64_array ( lracl , sizeof ( * lracl ) ) ; if ( txtype == TX_CREATE_ACL_ATTR || txtype == TX_MKDIR_ACL_ATTR ) { lrattr = ( lr_attr_t * ) ( caddr_t ) ( lracl + 1 ) ; zfs_replay_swap_attrs ( lrattr ) ; xvatlen = ZIL_XVAT_SIZE ( lrattr -> lr_attr_masksize ) ; } aclstart = ( caddr_t ) ( lracl + 1 ) + xvatlen ; zfs_ace_byteswap ( aclstart , lracl -> lr_acl_bytes , B_FALSE ) ; if ( lracl -> lr_fuidcnt ) { byteswap_uint64_array ( ( caddr_t ) aclstart + ZIL_ACE_LENGTH ( lracl -> lr_acl_bytes ) , lracl -> lr_fuidcnt * sizeof ( uint64_t ) ) ; } } if ( ( error = zfs_zget ( zfsvfs , lr -> lr_doid , & dzp ) ) != 0 ) return ( error ) ; xva_init ( & xva ) ; zfs_init_vattr ( & xva . xva_vattr , AT_TYPE | AT_MODE | AT_UID | AT_GID , lr -> lr_mode , lr -> lr_uid , lr -> lr_gid , lr -> lr_rdev , lr -> lr_foid ) ; ZFS_TIME_DECODE ( & xva . xva_vattr . va_ctime , lr -> lr_crtime ) ; xva . xva_vattr . va_nblocks = lr -> lr_gen ; error = dmu_object_info ( zfsvfs -> z_os , lr -> lr_foid , NULL ) ; if ( error != ENOENT ) goto bail ; if ( lr -> lr_common . lrc_txtype & TX_CI ) vflg |= FIGNORECASE ; switch ( txtype ) { case TX_CREATE_ACL : aclstart = ( caddr_t ) ( lracl + 1 ) ; fuidstart = ( caddr_t ) aclstart + ZIL_ACE_LENGTH ( lracl -> lr_acl_bytes ) ; zfsvfs -> z_fuid_replay = zfs_replay_fuids ( fuidstart , ( void * ) & name , lracl -> lr_fuidcnt , lracl -> lr_domcnt , lr -> lr_uid , lr -> lr_gid ) ; case TX_CREATE_ACL_ATTR : if ( name == NULL ) { lrattr = ( lr_attr_t * ) ( caddr_t ) ( lracl + 1 ) ; xvatlen = ZIL_XVAT_SIZE ( lrattr -> lr_attr_masksize ) ; xva . xva_vattr . va_mask |= AT_XVATTR ; zfs_replay_xvattr ( lrattr , & xva ) ; } vsec . vsa_mask = VSA_ACE | VSA_ACE_ACLFLAGS ; vsec . vsa_aclentp = ( caddr_t ) ( lracl + 1 ) + xvatlen ; vsec . vsa_aclcnt = lracl -> lr_aclcnt ; vsec . vsa_aclentsz = lracl -> lr_acl_bytes ; vsec . vsa_aclflags = lracl -> lr_acl_flags ; if ( zfsvfs -> z_fuid_replay == NULL ) { fuidstart = ( caddr_t ) ( lracl + 1 ) + xvatlen + ZIL_ACE_LENGTH ( lracl -> lr_acl_bytes ) ; zfsvfs -> z_fuid_replay = zfs_replay_fuids ( fuidstart , ( void * ) & name , lracl -> lr_fuidcnt , lracl -> lr_domcnt , lr -> lr_uid , lr -> lr_gid ) ; } #ifdef TODO error = VOP_CREATE ( ZTOV ( dzp ) , name , & xva . xva_vattr , 0 , 0 , & vp , kcred , vflg , NULL , & vsec ) ; #else panic ( " " , __func__ , __LINE__ ) ; #endif break ; case TX_MKDIR_ACL : aclstart = ( caddr_t ) ( lracl + 1 ) ; fuidstart = ( caddr_t ) aclstart + ZIL_ACE_LENGTH ( lracl -> lr_acl_bytes ) ; zfsvfs -> z_fuid_replay = zfs_replay_fuids ( fuidstart , ( void * ) & name , lracl -> lr_fuidcnt , lracl -> lr_domcnt , lr -> lr_uid , lr -> lr_gid ) ; case TX_MKDIR_ACL_ATTR : if ( name == NULL ) { lrattr = ( lr_attr_t * ) ( caddr_t ) ( lracl + 1 ) ; xvatlen = ZIL_XVAT_SIZE ( lrattr -> lr_attr_masksize ) ; zfs_replay_xvattr ( lrattr , & xva ) ; } vsec . vsa_mask = VSA_ACE | VSA_ACE_ACLFLAGS ; vsec . vsa_aclentp = ( caddr_t ) ( lracl + 1 ) + xvatlen ; vsec . vsa_aclcnt = lracl -> lr_aclcnt ; vsec . vsa_aclentsz = lracl -> lr_acl_bytes ; vsec . vsa_aclflags = lracl -> lr_acl_flags ; if ( zfsvfs -> z_fuid_replay == NULL ) { fuidstart = ( caddr_t ) ( lracl + 1 ) + xvatlen + ZIL_ACE_LENGTH ( lracl -> lr_acl_bytes ) ; zfsvfs -> z_fuid_replay = zfs_replay_fuids ( fuidstart , ( void * ) & name , lracl -> lr_fuidcnt , lracl -> lr_domcnt , lr -> lr_uid , lr -> lr_gid ) ; } #ifdef TODO error = VOP_MKDIR ( ZTOV ( dzp ) , name , & xva . xva_vattr , & vp , kcred , NULL , vflg , & vsec ) ; #else panic ( " " , __func__ , __LINE__ ) ; #endif break ; default : error = SET_ERROR ( ENOTSUP ) ; } bail : if ( error == 0 && vp != NULL ) VN_RELE ( vp ) ; VN_RELE ( ZTOV ( dzp ) ) ; if ( zfsvfs -> z_fuid_replay ) zfs_fuid_info_free ( zfsvfs -> z_fuid_replay ) ; zfsvfs -> z_fuid_replay = NULL ; return ( error ) ; }
Replay file create with optional ACL, xvattr information as well
 as option FUID information.
Replay file create with optional ACL xvattr information as well as option FUID information .
/* location determined later */ /* swap fuids */ /*
	 * All forms of zfs create (create, mkdir, mkxattrdir, symlink)
	 * eventually end up in zfs_mknode(), which assigns the object's
	 * creation time and generation number.  The generic VOP_CREATE()
	 * doesn't have either concept, so we smuggle the values inside
	 * the vattr's otherwise unused va_ctime and va_nblocks fields.
	 */ /*FALLTHROUGH*/ /*FALLTHROUGH*/