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

Change-Id: I066085a0606d64a0d95ab2d28340aa35d83efdf7
Signed-off-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.gerrithub.io/423504
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Changpeng Liu 2018-08-27 04:54:54 -04:00 committed by Ben Walker
parent ef61d9bcf8
commit 18261f8457
3 changed files with 32 additions and 3 deletions

View File

@ -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

View File

@ -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)
{

View File

@ -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
{
return 0;
int rc;
rc = spdk_file_get_id(mFile, id, max_size);
if (rc < 0) {
return 0;
} else {
return rc;
}
}
};