blobfs: change the return type of spdk_file_truncate

Change-Id: I29347d7b7be0237d7d604c7cd7363fa08a0cd025
Signed-off-by: Ziye Yang <optimistyzy@gmail.com>
Reviewed-on: https://review.gerrithub.io/420133
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
This commit is contained in:
Ziye Yang 2018-07-23 14:35:51 +08:00 committed by Changpeng Liu
parent d0b134606b
commit 703d1f80a8
6 changed files with 44 additions and 13 deletions

View File

@ -87,6 +87,11 @@ IOAT for copy engine is disabled by default. It can be enabled by specifying the
option with "Yes" in `[Ioat]` section of the configuration file. The Disable option is
now deprecated and will be removed in a future release.
### blobfs
Change the return type of spdk_file_truncate from void to int. The purpose is to catch
the `NOMEM` error condition.
## v18.04: Logical Volume Snapshot/Clone, iSCSI Initiator, Bdev QoS, VPP Userspace TCP/IP
### vhost

View File

@ -301,9 +301,11 @@ spdk_fs_iter spdk_fs_iter_next(spdk_fs_iter iter);
* \param file File to truncate.
* \param channel The I/O channel used to allocate file request.
* \param length New size in bytes of the file.
*
* \return 0 on success, negative errno on failure.
*/
void spdk_file_truncate(struct spdk_file *file, struct spdk_io_channel *channel,
uint64_t length);
int spdk_file_truncate(struct spdk_file *file, struct spdk_io_channel *channel,
uint64_t length);
/**
* Get file name.

View File

@ -1501,7 +1501,7 @@ __truncate(void *arg)
args->fn.file_op, args->arg);
}
void
int
spdk_file_truncate(struct spdk_file *file, struct spdk_io_channel *_channel,
uint64_t length)
{
@ -1510,7 +1510,9 @@ spdk_file_truncate(struct spdk_file *file, struct spdk_io_channel *_channel,
struct spdk_fs_cb_args *args;
req = alloc_fs_request(channel);
assert(req != NULL);
if (req == NULL) {
return -ENOMEM;
}
args = &req->args;
@ -1522,6 +1524,8 @@ spdk_file_truncate(struct spdk_file *file, struct spdk_io_channel *_channel,
channel->send_request(__truncate, req);
sem_wait(&channel->sem);
free_fs_request(req);
return 0;
}
static void

View File

@ -207,9 +207,15 @@ public:
virtual Status Truncate(uint64_t size) override
{
spdk_file_truncate(mFile, g_sync_args.channel, size);
mSize = size;
return Status::OK();
int rc;
rc = spdk_file_truncate(mFile, g_sync_args.channel, size);
if (!rc) {
mSize = size;
return Status::OK();
} else {
errno = -rc;
return Status::IOError(spdk_file_get_name(mFile), strerror(errno));
}
}
virtual Status Close() override
{
@ -246,8 +252,15 @@ public:
}
virtual Status Allocate(uint64_t offset, uint64_t len) override
{
spdk_file_truncate(mFile, g_sync_args.channel, offset + len);
return Status::OK();
int rc;
rc = spdk_file_truncate(mFile, g_sync_args.channel, offset + len);
if (!rc) {
return Status::OK();
} else {
errno = -rc;
return Status::IOError(spdk_file_get_name(mFile), strerror(errno));
}
}
virtual Status RangeSync(uint64_t offset, uint64_t nbytes) override
{

View File

@ -143,7 +143,11 @@ spdk_fuse_truncate(const char *path, off_t size, struct fuse_file_info *fi)
return -rc;
}
spdk_file_truncate(file, g_channel, size);
rc = spdk_file_truncate(file, g_channel, size);
if (rc != 0) {
return -rc;
}
spdk_file_close(file, g_channel);
return 0;

View File

@ -180,13 +180,15 @@ cache_write(void)
SPDK_CU_ASSERT_FATAL(g_file != NULL);
length = (4 * 1024 * 1024);
spdk_file_truncate(g_file, channel, length);
rc = spdk_file_truncate(g_file, channel, length);
CU_ASSERT(rc == 0);
spdk_file_write(g_file, channel, buf, 0, sizeof(buf));
CU_ASSERT(spdk_file_get_length(g_file) == length);
spdk_file_truncate(g_file, channel, sizeof(buf));
rc = spdk_file_truncate(g_file, channel, sizeof(buf));
CU_ASSERT(rc == 0);
spdk_file_close(g_file, channel);
rc = spdk_fs_delete_file(g_fs, channel, "testfile");
@ -218,7 +220,8 @@ cache_write_null_buffer(void)
SPDK_CU_ASSERT_FATAL(g_file != NULL);
length = 0;
spdk_file_truncate(g_file, channel, length);
rc = spdk_file_truncate(g_file, channel, length);
CU_ASSERT(rc == 0);
rc = spdk_file_write(g_file, channel, NULL, 0, 0);
CU_ASSERT(rc == 0);