diff --git a/include/spdk/blobfs.h b/include/spdk/blobfs.h index b8c521166..05d5d9990 100644 --- a/include/spdk/blobfs.h +++ b/include/spdk/blobfs.h @@ -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 diff --git a/lib/blobfs/blobfs.c b/lib/blobfs/blobfs.c index 7ac89fa6f..b8cedc41e 100644 --- a/lib/blobfs/blobfs.c +++ b/lib/blobfs/blobfs.c @@ -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) { diff --git a/lib/rocksdb/env_spdk.cc b/lib/rocksdb/env_spdk.cc index b86f46073..63c979eb9 100644 --- a/lib/rocksdb/env_spdk.cc +++ b/lib/rocksdb/env_spdk.cc @@ -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; + } } };