Commit 2caecd62 authored by Chaitanya Kulkarni's avatar Chaitanya Kulkarni Committed by Christoph Hellwig

nvmet: use i_size_read() to set size for file-ns

Instead of calling vfs_getattr() use i_size_read() to read the size of
file so we can read the size of not only file type but also block type
with one call. This is needed to implement buffered_io support for the
NVMeOF block device backend.

We also change return type of function nvmet_file_ns_revalidate() from
int to void, since this function does not return any meaning value.
Signed-off-by: default avatarChaitanya Kulkarni <kch@nvidia.com>
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
parent 581f19dd
...@@ -14,16 +14,9 @@ ...@@ -14,16 +14,9 @@
#define NVMET_MAX_MPOOL_BVEC 16 #define NVMET_MAX_MPOOL_BVEC 16
#define NVMET_MIN_MPOOL_OBJ 16 #define NVMET_MIN_MPOOL_OBJ 16
int nvmet_file_ns_revalidate(struct nvmet_ns *ns) void nvmet_file_ns_revalidate(struct nvmet_ns *ns)
{ {
struct kstat stat; ns->size = i_size_read(ns->file->f_mapping->host);
int ret;
ret = vfs_getattr(&ns->file->f_path, &stat, STATX_SIZE,
AT_STATX_FORCE_SYNC);
if (!ret)
ns->size = stat.size;
return ret;
} }
void nvmet_file_ns_disable(struct nvmet_ns *ns) void nvmet_file_ns_disable(struct nvmet_ns *ns)
...@@ -43,7 +36,7 @@ void nvmet_file_ns_disable(struct nvmet_ns *ns) ...@@ -43,7 +36,7 @@ void nvmet_file_ns_disable(struct nvmet_ns *ns)
int nvmet_file_ns_enable(struct nvmet_ns *ns) int nvmet_file_ns_enable(struct nvmet_ns *ns)
{ {
int flags = O_RDWR | O_LARGEFILE; int flags = O_RDWR | O_LARGEFILE;
int ret; int ret = 0;
if (!ns->buffered_io) if (!ns->buffered_io)
flags |= O_DIRECT; flags |= O_DIRECT;
...@@ -57,9 +50,7 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns) ...@@ -57,9 +50,7 @@ int nvmet_file_ns_enable(struct nvmet_ns *ns)
return ret; return ret;
} }
ret = nvmet_file_ns_revalidate(ns); nvmet_file_ns_revalidate(ns);
if (ret)
goto err;
/* /*
* i_blkbits can be greater than the universally accepted upper bound, * i_blkbits can be greater than the universally accepted upper bound,
......
...@@ -541,7 +541,7 @@ u16 nvmet_bdev_flush(struct nvmet_req *req); ...@@ -541,7 +541,7 @@ u16 nvmet_bdev_flush(struct nvmet_req *req);
u16 nvmet_file_flush(struct nvmet_req *req); u16 nvmet_file_flush(struct nvmet_req *req);
void nvmet_ns_changed(struct nvmet_subsys *subsys, u32 nsid); void nvmet_ns_changed(struct nvmet_subsys *subsys, u32 nsid);
void nvmet_bdev_ns_revalidate(struct nvmet_ns *ns); void nvmet_bdev_ns_revalidate(struct nvmet_ns *ns);
int nvmet_file_ns_revalidate(struct nvmet_ns *ns); void nvmet_file_ns_revalidate(struct nvmet_ns *ns);
void nvmet_ns_revalidate(struct nvmet_ns *ns); void nvmet_ns_revalidate(struct nvmet_ns *ns);
u16 blk_to_nvme_status(struct nvmet_req *req, blk_status_t blk_sts); u16 blk_to_nvme_status(struct nvmet_req *req, blk_status_t blk_sts);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment