spitting up ublksrv_tgt.cpp

3 views
Skip to first unread message

ronnie sahlberg

unread,
Mar 8, 2025, 1:06:29 PMMar 8
to ub...@googlegroups.com
I have some thoughts about splitting up targets/ublksrv_tct.cpp
but it looks to be quite hairy to do this in a nice way so want to see what others think.

The first thing is that ublksrv_tgt contains a new-we API for managing the jsob blobs
compared to the public lib/ublksrv_json.cpp code.
The new api is much nicer since it it is threads safe and also hides the jbuf implementation and makes it automatically adjust the buffer size.

The only in-tree consumers of the old api are the demo_*.c examples.
I propose to convert the demo* examples over to use the new API,
the document the old API in the public headers as deprecated
and move the json functions from targets/ublksrv_tgt.cpp to lib/ublksrv_json.cpp and make them the new non-deprecated API.


After migrating the json API out of ublksrv_tgt.cpp,   the (almost) only thing remaning in
ublksrv_tgt.cpp will now be ublksrv_tgt_cmd_main() and all the code that it depends on.
While a lot of code it is pretty much just boilerplate for creating/recovering a target with all target-specific code is passed in via the ublksrv_tgt_type pointer.

So let's move it all into the public library and make ublksrv_tgt_cmd_main() a public symbol that all ublk.<type> targets can use.


Ming Lei

unread,
Mar 9, 2025, 11:11:30 AMMar 9
to ronnie sahlberg, ub...@googlegroups.com
On Sun, Mar 09, 2025 at 04:06:16AM +1000, ronnie sahlberg wrote:
> I have some thoughts about splitting up targets/ublksrv_tct.cpp
> but it looks to be quite hairy to do this in a nice way so want to see what
> others think.
>
> The first thing is that ublksrv_tgt contains a new-we API for managing the
> jsob blobs
> compared to the public lib/ublksrv_json.cpp code.
> The new api is much nicer since it it is threads safe and also hides the
> jbuf implementation and makes it automatically adjust the buffer size.
>
> The only in-tree consumers of the old api are the demo_*.c examples.
> I propose to convert the demo* examples over to use the new API,
> the document the old API in the public headers as deprecated
> and move the json functions from targets/ublksrv_tgt.cpp to
> lib/ublksrv_json.cpp and make them the new non-deprecated API.

demo_*.c is supposed to be against public API only, so the new APIs
need to become public first.

>
>
> After migrating the json API out of ublksrv_tgt.cpp, the (almost) only
> thing remaning in
> ublksrv_tgt.cpp will now be ublksrv_tgt_cmd_main() and all the code that it
> depends on.
> While a lot of code it is pretty much just boilerplate for
> creating/recovering a target with all target-specific code is passed in via
> the ublksrv_tgt_type pointer.
>
> So let's move it all into the public library and
> make ublksrv_tgt_cmd_main() a public symbol that all ublk.<type> targets
> can use.

I think it is fine to move new json APIs into libublksrv, but I guess it may
need to rework a bit.


Thanks,
Ming
Reply all
Reply to author
Forward
0 new messages