Remove zfs_getattr and convoff dead code

The `convoff` function is called only in one code path in `zfs_space`.
Each caller of `zfs_space` is called with a `flock64_t` that has
`l_whence` set to `SEEK_SET`. This means that `convoff` always results
in a no-op as the `bfp` parameter has `l_whence` set to `SEEK_SET` and
`int whence` is `SEEK_SET` as well.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by:  Ryan Moeller <ryan@iXsystems.com>
Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
Closes #10006
This commit is contained in:
Dirkjan Bussink 2020-02-25 00:38:23 +01:00 committed by GitHub
parent 92bd4cabd6
commit 327000ce04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1 additions and 269 deletions

View File

@ -59,7 +59,6 @@ extern int zfs_rmdir(znode_t *dzp, char *name, znode_t *cwd,
cred_t *cr, int flags); cred_t *cr, int flags);
extern int zfs_readdir(struct inode *ip, zpl_dir_context_t *ctx, cred_t *cr); extern int zfs_readdir(struct inode *ip, zpl_dir_context_t *ctx, cred_t *cr);
extern int zfs_fsync(znode_t *zp, int syncflag, cred_t *cr); extern int zfs_fsync(znode_t *zp, int syncflag, cred_t *cr);
extern int zfs_getattr(struct inode *ip, vattr_t *vap, int flag, cred_t *cr);
extern int zfs_getattr_fast(struct inode *ip, struct kstat *sp); extern int zfs_getattr_fast(struct inode *ip, struct kstat *sp);
extern int zfs_setattr(znode_t *zp, vattr_t *vap, int flag, cred_t *cr); extern int zfs_setattr(znode_t *zp, vattr_t *vap, int flag, cred_t *cr);
extern int zfs_rename(znode_t *sdzp, char *snm, znode_t *tdzp, extern int zfs_rename(znode_t *sdzp, char *snm, znode_t *tdzp,

View File

@ -938,7 +938,7 @@ void dmu_object_info_from_dnode(dnode_t *dn, dmu_object_info_t *doi);
void dmu_object_info_from_db(dmu_buf_t *db, dmu_object_info_t *doi); void dmu_object_info_from_db(dmu_buf_t *db, dmu_object_info_t *doi);
/* /*
* Like dmu_object_info_from_db, but faster still when you only care about * Like dmu_object_info_from_db, but faster still when you only care about
* the size. This is specifically optimized for zfs_getattr(). * the size.
*/ */
void dmu_object_size_from_db(dmu_buf_t *db, uint32_t *blksize, void dmu_object_size_from_db(dmu_buf_t *db, uint32_t *blksize,
u_longlong_t *nblk512); u_longlong_t *nblk512);

View File

@ -2451,218 +2451,6 @@ zfs_fsync(znode_t *zp, int syncflag, cred_t *cr)
return (0); return (0);
} }
/*
* Get the requested file attributes and place them in the provided
* vattr structure.
*
* IN: ip - inode of file.
* vap - va_mask identifies requested attributes.
* If ATTR_XVATTR set, then optional attrs are requested
* flags - ATTR_NOACLCHECK (CIFS server context)
* cr - credentials of caller.
*
* OUT: vap - attribute values.
*
* RETURN: 0 (always succeeds)
*/
/* ARGSUSED */
int
zfs_getattr(struct inode *ip, vattr_t *vap, int flags, cred_t *cr)
{
znode_t *zp = ITOZ(ip);
zfsvfs_t *zfsvfs = ITOZSB(ip);
int error = 0;
uint64_t links;
uint64_t atime[2], mtime[2], ctime[2];
xvattr_t *xvap = (xvattr_t *)vap; /* vap may be an xvattr_t * */
xoptattr_t *xoap = NULL;
boolean_t skipaclchk = (flags & ATTR_NOACLCHECK) ? B_TRUE : B_FALSE;
sa_bulk_attr_t bulk[3];
int count = 0;
ZFS_ENTER(zfsvfs);
ZFS_VERIFY_ZP(zp);
zfs_fuid_map_ids(zp, cr, &vap->va_uid, &vap->va_gid);
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_ATIME(zfsvfs), NULL, &atime, 16);
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL, &mtime, 16);
SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, &ctime, 16);
if ((error = sa_bulk_lookup(zp->z_sa_hdl, bulk, count)) != 0) {
ZFS_EXIT(zfsvfs);
return (error);
}
/*
* If ACL is trivial don't bother looking for ACE_READ_ATTRIBUTES.
* Also, if we are the owner don't bother, since owner should
* always be allowed to read basic attributes of file.
*/
if (!(zp->z_pflags & ZFS_ACL_TRIVIAL) &&
(vap->va_uid != crgetuid(cr))) {
if ((error = zfs_zaccess(zp, ACE_READ_ATTRIBUTES, 0,
skipaclchk, cr))) {
ZFS_EXIT(zfsvfs);
return (error);
}
}
/*
* Return all attributes. It's cheaper to provide the answer
* than to determine whether we were asked the question.
*/
mutex_enter(&zp->z_lock);
vap->va_mode = zp->z_mode;
vap->va_fsid = ZTOI(zp)->i_sb->s_dev;
vap->va_nodeid = zp->z_id;
if ((zp->z_id == zfsvfs->z_root) && zfs_show_ctldir(zp))
links = ZTOI(zp)->i_nlink + 1;
else
links = ZTOI(zp)->i_nlink;
vap->va_nlink = MIN(links, ZFS_LINK_MAX);
vap->va_size = i_size_read(ip);
vap->va_rdev = ip->i_rdev;
/*
* Add in any requested optional attributes and the create time.
* Also set the corresponding bits in the returned attribute bitmap.
*/
if ((xoap = xva_getxoptattr(xvap)) != NULL && zfsvfs->z_use_fuids) {
if (XVA_ISSET_REQ(xvap, XAT_ARCHIVE)) {
xoap->xoa_archive =
((zp->z_pflags & ZFS_ARCHIVE) != 0);
XVA_SET_RTN(xvap, XAT_ARCHIVE);
}
if (XVA_ISSET_REQ(xvap, XAT_READONLY)) {
xoap->xoa_readonly =
((zp->z_pflags & ZFS_READONLY) != 0);
XVA_SET_RTN(xvap, XAT_READONLY);
}
if (XVA_ISSET_REQ(xvap, XAT_SYSTEM)) {
xoap->xoa_system =
((zp->z_pflags & ZFS_SYSTEM) != 0);
XVA_SET_RTN(xvap, XAT_SYSTEM);
}
if (XVA_ISSET_REQ(xvap, XAT_HIDDEN)) {
xoap->xoa_hidden =
((zp->z_pflags & ZFS_HIDDEN) != 0);
XVA_SET_RTN(xvap, XAT_HIDDEN);
}
if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) {
xoap->xoa_nounlink =
((zp->z_pflags & ZFS_NOUNLINK) != 0);
XVA_SET_RTN(xvap, XAT_NOUNLINK);
}
if (XVA_ISSET_REQ(xvap, XAT_IMMUTABLE)) {
xoap->xoa_immutable =
((zp->z_pflags & ZFS_IMMUTABLE) != 0);
XVA_SET_RTN(xvap, XAT_IMMUTABLE);
}
if (XVA_ISSET_REQ(xvap, XAT_APPENDONLY)) {
xoap->xoa_appendonly =
((zp->z_pflags & ZFS_APPENDONLY) != 0);
XVA_SET_RTN(xvap, XAT_APPENDONLY);
}
if (XVA_ISSET_REQ(xvap, XAT_NODUMP)) {
xoap->xoa_nodump =
((zp->z_pflags & ZFS_NODUMP) != 0);
XVA_SET_RTN(xvap, XAT_NODUMP);
}
if (XVA_ISSET_REQ(xvap, XAT_OPAQUE)) {
xoap->xoa_opaque =
((zp->z_pflags & ZFS_OPAQUE) != 0);
XVA_SET_RTN(xvap, XAT_OPAQUE);
}
if (XVA_ISSET_REQ(xvap, XAT_AV_QUARANTINED)) {
xoap->xoa_av_quarantined =
((zp->z_pflags & ZFS_AV_QUARANTINED) != 0);
XVA_SET_RTN(xvap, XAT_AV_QUARANTINED);
}
if (XVA_ISSET_REQ(xvap, XAT_AV_MODIFIED)) {
xoap->xoa_av_modified =
((zp->z_pflags & ZFS_AV_MODIFIED) != 0);
XVA_SET_RTN(xvap, XAT_AV_MODIFIED);
}
if (XVA_ISSET_REQ(xvap, XAT_AV_SCANSTAMP) &&
S_ISREG(ip->i_mode)) {
zfs_sa_get_scanstamp(zp, xvap);
}
if (XVA_ISSET_REQ(xvap, XAT_CREATETIME)) {
uint64_t times[2];
(void) sa_lookup(zp->z_sa_hdl, SA_ZPL_CRTIME(zfsvfs),
times, sizeof (times));
ZFS_TIME_DECODE(&xoap->xoa_createtime, times);
XVA_SET_RTN(xvap, XAT_CREATETIME);
}
if (XVA_ISSET_REQ(xvap, XAT_REPARSE)) {
xoap->xoa_reparse = ((zp->z_pflags & ZFS_REPARSE) != 0);
XVA_SET_RTN(xvap, XAT_REPARSE);
}
if (XVA_ISSET_REQ(xvap, XAT_GEN)) {
xoap->xoa_generation = ip->i_generation;
XVA_SET_RTN(xvap, XAT_GEN);
}
if (XVA_ISSET_REQ(xvap, XAT_OFFLINE)) {
xoap->xoa_offline =
((zp->z_pflags & ZFS_OFFLINE) != 0);
XVA_SET_RTN(xvap, XAT_OFFLINE);
}
if (XVA_ISSET_REQ(xvap, XAT_SPARSE)) {
xoap->xoa_sparse =
((zp->z_pflags & ZFS_SPARSE) != 0);
XVA_SET_RTN(xvap, XAT_SPARSE);
}
if (XVA_ISSET_REQ(xvap, XAT_PROJINHERIT)) {
xoap->xoa_projinherit =
((zp->z_pflags & ZFS_PROJINHERIT) != 0);
XVA_SET_RTN(xvap, XAT_PROJINHERIT);
}
if (XVA_ISSET_REQ(xvap, XAT_PROJID)) {
xoap->xoa_projid = zp->z_projid;
XVA_SET_RTN(xvap, XAT_PROJID);
}
}
ZFS_TIME_DECODE(&vap->va_atime, atime);
ZFS_TIME_DECODE(&vap->va_mtime, mtime);
ZFS_TIME_DECODE(&vap->va_ctime, ctime);
mutex_exit(&zp->z_lock);
sa_object_size(zp->z_sa_hdl, &vap->va_blksize, &vap->va_nblocks);
if (zp->z_blksz == 0) {
/*
* Block size hasn't been set; suggest maximal I/O transfers.
*/
vap->va_blksize = zfsvfs->z_max_blksz;
}
ZFS_EXIT(zfsvfs);
return (0);
}
/* /*
* Get the basic file attributes and place them in the provided kstat * Get the basic file attributes and place them in the provided kstat
* structure. The inode is assumed to be the authoritative source * structure. The inode is assumed to be the authoritative source
@ -4901,54 +4689,6 @@ zfs_map(struct inode *ip, offset_t off, caddr_t *addrp, size_t len,
return (0); return (0);
} }
/*
* convoff - converts the given data (start, whence) to the
* given whence.
*/
int
convoff(struct inode *ip, flock64_t *lckdat, int whence, offset_t offset)
{
vattr_t vap;
int error;
if ((lckdat->l_whence == SEEK_END) || (whence == SEEK_END)) {
if ((error = zfs_getattr(ip, &vap, 0, CRED())))
return (error);
}
switch (lckdat->l_whence) {
case SEEK_CUR:
lckdat->l_start += offset;
break;
case SEEK_END:
lckdat->l_start += vap.va_size;
/* FALLTHRU */
case SEEK_SET:
break;
default:
return (SET_ERROR(EINVAL));
}
if (lckdat->l_start < 0)
return (SET_ERROR(EINVAL));
switch (whence) {
case SEEK_CUR:
lckdat->l_start -= offset;
break;
case SEEK_END:
lckdat->l_start -= vap.va_size;
/* FALLTHRU */
case SEEK_SET:
break;
default:
return (SET_ERROR(EINVAL));
}
lckdat->l_whence = (short)whence;
return (0);
}
/* /*
* Free or allocate space in a file. Currently, this function only * Free or allocate space in a file. Currently, this function only
* supports the `F_FREESP' command. However, this command is somewhat * supports the `F_FREESP' command. However, this command is somewhat
@ -4993,11 +4733,6 @@ zfs_space(znode_t *zp, int cmd, flock64_t *bfp, int flag,
return (SET_ERROR(EROFS)); return (SET_ERROR(EROFS));
} }
if ((error = convoff(ZTOI(zp), bfp, SEEK_SET, offset))) {
ZFS_EXIT(zfsvfs);
return (error);
}
if (bfp->l_len < 0) { if (bfp->l_len < 0) {
ZFS_EXIT(zfsvfs); ZFS_EXIT(zfsvfs);
return (SET_ERROR(EINVAL)); return (SET_ERROR(EINVAL));
@ -5274,7 +5009,6 @@ EXPORT_SYMBOL(zfs_mkdir);
EXPORT_SYMBOL(zfs_rmdir); EXPORT_SYMBOL(zfs_rmdir);
EXPORT_SYMBOL(zfs_readdir); EXPORT_SYMBOL(zfs_readdir);
EXPORT_SYMBOL(zfs_fsync); EXPORT_SYMBOL(zfs_fsync);
EXPORT_SYMBOL(zfs_getattr);
EXPORT_SYMBOL(zfs_getattr_fast); EXPORT_SYMBOL(zfs_getattr_fast);
EXPORT_SYMBOL(zfs_setattr); EXPORT_SYMBOL(zfs_setattr);
EXPORT_SYMBOL(zfs_rename); EXPORT_SYMBOL(zfs_rename);

View File

@ -2365,7 +2365,6 @@ dmu_object_info_from_db(dmu_buf_t *db_fake, dmu_object_info_t *doi)
/* /*
* Faster still when you only care about the size. * Faster still when you only care about the size.
* This is specifically optimized for zfs_getattr().
*/ */
void void
dmu_object_size_from_db(dmu_buf_t *db_fake, uint32_t *blksize, dmu_object_size_from_db(dmu_buf_t *db_fake, uint32_t *blksize,