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:
parent
d0b134606b
commit
703d1f80a8
@ -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
|
option with "Yes" in `[Ioat]` section of the configuration file. The Disable option is
|
||||||
now deprecated and will be removed in a future release.
|
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
|
## v18.04: Logical Volume Snapshot/Clone, iSCSI Initiator, Bdev QoS, VPP Userspace TCP/IP
|
||||||
|
|
||||||
### vhost
|
### vhost
|
||||||
|
@ -301,8 +301,10 @@ spdk_fs_iter spdk_fs_iter_next(spdk_fs_iter iter);
|
|||||||
* \param file File to truncate.
|
* \param file File to truncate.
|
||||||
* \param channel The I/O channel used to allocate file request.
|
* \param channel The I/O channel used to allocate file request.
|
||||||
* \param length New size in bytes of the file.
|
* \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,
|
int spdk_file_truncate(struct spdk_file *file, struct spdk_io_channel *channel,
|
||||||
uint64_t length);
|
uint64_t length);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1501,7 +1501,7 @@ __truncate(void *arg)
|
|||||||
args->fn.file_op, args->arg);
|
args->fn.file_op, args->arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int
|
||||||
spdk_file_truncate(struct spdk_file *file, struct spdk_io_channel *_channel,
|
spdk_file_truncate(struct spdk_file *file, struct spdk_io_channel *_channel,
|
||||||
uint64_t length)
|
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;
|
struct spdk_fs_cb_args *args;
|
||||||
|
|
||||||
req = alloc_fs_request(channel);
|
req = alloc_fs_request(channel);
|
||||||
assert(req != NULL);
|
if (req == NULL) {
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
args = &req->args;
|
args = &req->args;
|
||||||
|
|
||||||
@ -1522,6 +1524,8 @@ spdk_file_truncate(struct spdk_file *file, struct spdk_io_channel *_channel,
|
|||||||
channel->send_request(__truncate, req);
|
channel->send_request(__truncate, req);
|
||||||
sem_wait(&channel->sem);
|
sem_wait(&channel->sem);
|
||||||
free_fs_request(req);
|
free_fs_request(req);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -207,9 +207,15 @@ public:
|
|||||||
|
|
||||||
virtual Status Truncate(uint64_t size) override
|
virtual Status Truncate(uint64_t size) override
|
||||||
{
|
{
|
||||||
spdk_file_truncate(mFile, g_sync_args.channel, size);
|
int rc;
|
||||||
|
rc = spdk_file_truncate(mFile, g_sync_args.channel, size);
|
||||||
|
if (!rc) {
|
||||||
mSize = size;
|
mSize = size;
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
|
} else {
|
||||||
|
errno = -rc;
|
||||||
|
return Status::IOError(spdk_file_get_name(mFile), strerror(errno));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
virtual Status Close() override
|
virtual Status Close() override
|
||||||
{
|
{
|
||||||
@ -246,8 +252,15 @@ public:
|
|||||||
}
|
}
|
||||||
virtual Status Allocate(uint64_t offset, uint64_t len) override
|
virtual Status Allocate(uint64_t offset, uint64_t len) override
|
||||||
{
|
{
|
||||||
spdk_file_truncate(mFile, g_sync_args.channel, offset + len);
|
int rc;
|
||||||
|
|
||||||
|
rc = spdk_file_truncate(mFile, g_sync_args.channel, offset + len);
|
||||||
|
if (!rc) {
|
||||||
return Status::OK();
|
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
|
virtual Status RangeSync(uint64_t offset, uint64_t nbytes) override
|
||||||
{
|
{
|
||||||
|
@ -143,7 +143,11 @@ spdk_fuse_truncate(const char *path, off_t size, struct fuse_file_info *fi)
|
|||||||
return -rc;
|
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);
|
spdk_file_close(file, g_channel);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -180,13 +180,15 @@ cache_write(void)
|
|||||||
SPDK_CU_ASSERT_FATAL(g_file != NULL);
|
SPDK_CU_ASSERT_FATAL(g_file != NULL);
|
||||||
|
|
||||||
length = (4 * 1024 * 1024);
|
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));
|
spdk_file_write(g_file, channel, buf, 0, sizeof(buf));
|
||||||
|
|
||||||
CU_ASSERT(spdk_file_get_length(g_file) == length);
|
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);
|
spdk_file_close(g_file, channel);
|
||||||
rc = spdk_fs_delete_file(g_fs, channel, "testfile");
|
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);
|
SPDK_CU_ASSERT_FATAL(g_file != NULL);
|
||||||
|
|
||||||
length = 0;
|
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);
|
rc = spdk_file_write(g_file, channel, NULL, 0, 0);
|
||||||
CU_ASSERT(rc == 0);
|
CU_ASSERT(rc == 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user