]> www.infradead.org Git - users/sagi/libnvme.git/commit
sysfs: minimize heap allocations of sysfs paths
authorCaleb Sander Mateos <csander@purestorage.com>
Tue, 19 Mar 2024 19:23:51 +0000 (13:23 -0600)
committerDaniel Wagner <wagi@monom.org>
Wed, 20 Mar 2024 07:28:52 +0000 (08:28 +0100)
commiteb4f79477b74d777f6ab66dfa009fe45f1ca3da1
tree04774418a84840e93f3bcb52cc180d7fd75a56e6
parentc2f23b36e800cf2eacfff1e75f304dc9ba05a609
sysfs: minimize heap allocations of sysfs paths

11a0918a9972 ("nvme: allow to overwrite base sysfs path")
added support for changing the sysfs path via an environment variable.
Unfortunately, it added a heap allocation
every time a sysfs path was requested.

Modify the callers to not free the paths, which allows a string constant
to be returned if the path isn't overridden, avoiding an allocation.
Cache the path in a static variable so that if it is overridden,
the heap-allocated string only needs to be constructed once
and afterwards can be reused.

Create a file sysfs.c to consolidate this logic
instead of spreading them across 3 files.
Also introduce a helper to factor out the duplicated code.

Fixes: 11a0918a9972 ("nvme: allow to overwrite base sysfs path")
Signed-off-by: Caleb Sander Mateos <csander@purestorage.com>
src/meson.build
src/nvme/fabrics.c
src/nvme/filters.c
src/nvme/private.h
src/nvme/sysfs.c [new file with mode: 0644]
src/nvme/tree.c