loff_t *pos, cred_t *cr);
extern int zfs_fsync(struct inode *ip, 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_setattr(struct inode *ip, vattr_t *vap, int flag, cred_t *cr);
extern int zfs_rename(struct inode *sdip, char *snm, struct inode *tdip,
char *tnm, cred_t *cr, int flags);
}
EXPORT_SYMBOL(zfs_getattr);
+/*
+ * Get the basic file attributes and place them in the provided kstat
+ * structure. The inode is assumed to be the authoritative source
+ * for most of the attributes. However, the znode currently has the
+ * authoritative atime, blksize, and block count.
+ *
+ * IN: ip - inode of file.
+ *
+ * OUT: sp - kstat values.
+ *
+ * RETURN: 0 (always succeeds)
+ */
+/* ARGSUSED */
+int
+zfs_getattr_fast(struct inode *ip, struct kstat *sp)
+{
+ znode_t *zp = ITOZ(ip);
+ zfs_sb_t *zsb = ITOZSB(ip);
+
+ mutex_enter(&zp->z_lock);
+
+ generic_fillattr(ip, sp);
+ ZFS_TIME_DECODE(&sp->atime, zp->z_atime);
+
+ sa_object_size(zp->z_sa_hdl, (uint32_t *)&sp->blksize, &sp->blocks);
+ if (unlikely(zp->z_blksz == 0)) {
+ /*
+ * Block size hasn't been set; suggest maximal I/O transfers.
+ */
+ sp->blksize = zsb->z_max_blksz;
+ }
+
+ mutex_exit(&zp->z_lock);
+
+ return (0);
+}
+EXPORT_SYMBOL(zfs_getattr_fast);
+
/*
* Set the file attributes to the values contained in the
* vattr structure.
static int
zpl_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
{
- cred_t *cr = CRED();
- vattr_t *vap;
- struct inode *ip;
int error;
- ip = dentry->d_inode;
- crhold(cr);
- vap = kmem_zalloc(sizeof(vattr_t), KM_SLEEP);
-
- error = -zfs_getattr(ip, vap, 0, cr);
- if (error)
- goto out;
-
- stat->ino = ip->i_ino;
- stat->dev = ip->i_sb->s_dev;
- stat->mode = vap->va_mode;
- stat->nlink = vap->va_nlink;
- stat->uid = vap->va_uid;
- stat->gid = vap->va_gid;
- stat->rdev = vap->va_rdev;
- stat->size = vap->va_size;
- stat->atime = vap->va_atime;
- stat->mtime = vap->va_mtime;
- stat->ctime = vap->va_ctime;
- stat->blksize = vap->va_blksize;
- stat->blocks = vap->va_nblocks;
-out:
- kmem_free(vap, sizeof(vattr_t));
- crfree(cr);
+ error = -zfs_getattr_fast(dentry->d_inode, stat);
ASSERT3S(error, <=, 0);
return (error);