Skip to content

Commit fb628fe

Browse files
committed
util: add function to retrieve version information
Allow to query the version of the library via a function. Signed-off-by: Daniel Wagner <[email protected]>
1 parent 1503223 commit fb628fe

4 files changed

Lines changed: 37 additions & 0 deletions

File tree

meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ else
4646
check: true)
4747
conf.set('GIT_VERSION', '"@0@"'.format(r.stdout().strip()))
4848
endif
49+
conf.set('PROJECT_VERSION', '"@0@"'.format(meson.project_version()))
4950

5051
conf.set('SYSCONFDIR', '"@0@"'.format(sysconfdir))
5152

src/libnvme.map

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
LIBNVME_1_1 {
2+
global:
3+
nvme_get_version;
4+
};
5+
16
LIBNVME_1_0 {
27
global:
38
nvme_admin_passthru64;

src/nvme/util.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,3 +778,15 @@ struct nvmf_ext_attr *nvmf_exat_ptr_next(struct nvmf_ext_attr *p)
778778
return (struct nvmf_ext_attr *)
779779
((uintptr_t)p + (ptrdiff_t)nvmf_exat_size(le16_to_cpu(p->exatlen)));
780780
}
781+
782+
const char *nvme_get_version(enum nvme_version type)
783+
{
784+
switch(type) {
785+
case NVME_VERSION_PROJECT:
786+
return PROJECT_VERSION;
787+
case NVME_VERSION_GIT:
788+
return GIT_VERSION;
789+
default:
790+
return "n/a";
791+
}
792+
}

src/nvme/util.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,4 +532,23 @@ static inline __u16 nvmf_exat_size(size_t val_len)
532532
*/
533533
struct nvmf_ext_attr *nvmf_exat_ptr_next(struct nvmf_ext_attr *p);
534534

535+
/**
536+
* enum nvme_version - Selector for version to be returned by @nvme_get_version
537+
*
538+
* NVME_VERSION_PROJECT: Project release version
539+
* NVME_VERSION_GIT: Git reference
540+
*/
541+
enum nvme_version {
542+
NVME_VERSION_PROJECT = 0,
543+
NVME_VERSION_GIT = 1,
544+
};
545+
546+
/**
547+
* nvme_get_version - Return version libnvme string
548+
* @type: Selects which version type (see @struct nvme_version)
549+
*
550+
* Return: Returns version string for known types or else "n/a"
551+
*/
552+
const char *nvme_get_version(enum nvme_version type);
553+
535554
#endif /* _LIBNVME_UTIL_H */

0 commit comments

Comments
 (0)