Commit 703d1f80 authored by Ziye Yang's avatar Ziye Yang Committed by Changpeng Liu
Browse files

blobfs: change the return type of spdk_file_truncate



Change-Id: I29347d7b7be0237d7d604c7cd7363fa08a0cd025
Signed-off-by: default avatarZiye Yang <optimistyzy@gmail.com>
Reviewed-on: https://review.gerrithub.io/420133


Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
parent d0b13460
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -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
+4 −2
Original line number Diff line number Diff line
@@ -301,8 +301,10 @@ 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,
int spdk_file_truncate(struct spdk_file *file, struct spdk_io_channel *channel,
		       uint64_t length);

/**
+6 −2
Original line number Diff line number Diff line
@@ -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
+18 −5
Original line number Diff line number Diff line
@@ -207,9 +207,15 @@ public:

	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;
			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);
		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
	{
+5 −1
Original line number Diff line number Diff line
@@ -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;
Loading