Commit 18261f84 authored by Changpeng Liu's avatar Changpeng Liu Committed by Ben Walker
Browse files

blobfs: add a new API to return file's unique ID



Change-Id: I066085a0606d64a0d95ab2d28340aa35d83efdf7
Signed-off-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.gerrithub.io/423504


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent ef61d9bc
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -388,6 +388,17 @@ void spdk_file_set_priority(struct spdk_file *file, uint32_t priority);
 */
int spdk_file_sync(struct spdk_file *file, struct spdk_io_channel *channel);

/**
 * Get the unique ID for the file.
 *
 * \param file File to get the ID.
 * \param id ID buffer.
 * \param size Size of the ID buffer.
 *
 * \return the length of ID on success.
 */
int spdk_file_get_id(struct spdk_file *file, void *id, size_t size);

#ifdef __cplusplus
}
#endif
+12 −0
Original line number Diff line number Diff line
@@ -2576,6 +2576,18 @@ spdk_file_close(struct spdk_file *file, struct spdk_io_channel *_channel)
	return args->rc;
}

int
spdk_file_get_id(struct spdk_file *file, void *id, size_t size)
{
	if (size < sizeof(spdk_blob_id)) {
		return -EINVAL;
	}

	memcpy(id, &file->blobid, sizeof(spdk_blob_id));

	return sizeof(spdk_blob_id);
}

static void
cache_free_buffers(struct spdk_file *file)
{
+9 −3
Original line number Diff line number Diff line
@@ -308,10 +308,16 @@ public:
			return Status::IOError(spdk_file_get_name(mFile), strerror(errno));
		}
	}
	virtual size_t GetUniqueId(__attribute__((unused)) char *id,
				   __attribute__((unused)) size_t max_size) const override
	virtual size_t GetUniqueId(char *id, size_t max_size) const override
	{
		int rc;

		rc = spdk_file_get_id(mFile, id, max_size);
		if (rc < 0) {
			return 0;
		} else {
			return rc;
		}
	}
};