libublk-rs icon indicating copy to clipboard operation
libublk-rs copied to clipboard

Working on existing devices?

Open gaurangtapase opened this issue 1 year ago • 9 comments

Hello, is the rust library compatible with the devices created by ublksrv. Currently, I am not able to fully get the dev info from UblkCtrl for the already created devices.

gaurangtapase avatar Feb 20 '25 19:02 gaurangtapase

It would be useful to have an example program showing a UblkCtrlBuilder getter, for example something like "ublk list -n 27" but in rust using the rust library,

So that you could view and maybe also manage existing devices in addition to creating new devices.

sahlberg avatar Feb 21 '25 00:02 sahlberg

The main job is done by add command, so once device is added, there is little thing left, so far, just 'list', 'remove', 'recover', ...

libublk-rs can run 'list', 'remove' for existing devices, because it is just enough to do that by providing device id.

But 'recover' is a bit different, which is 99% same with handling add command, and it requires same pid file. However, if your rust implementation based on libublk-rs does same thing with the other implementation for adding the device, it is fine to recover by libublk-rs based application.

I am not able to fully get the dev info from UblkCtrl for the already created devices.

I guess you are using rublk, which only list devices with rublk pid file path, so the device isn't listed.

However, libublk-rs is capable of doing that, please try it with the latest libublk-rs which just adds '-n' argument for example null.

cargo run --example null list -n 0

ming1 avatar Feb 21 '25 04:02 ming1

Hi @ming1 , Thanks for the response. My apologies I didn't make this clear in my request.

Basically, can we create a ublk device from ublksrv and then expect it to be usable by ublklib-rs?

From my simple test (creating a ublkCtrl using new_simple and use dump() to get the ublk device info. It doesn't seem to be working (especially doesn't show the target json data)

./ublklib_test 
device reload json failed

dev id 3: nr_hw_queues 1 queue_depth 128 block size 4096 dev_capacity 0
	max rq size 524288 daemon pid 124008 flags 0x42 state LIVE
	ublkc: 235:3 ublkb: 259:0 owner: 0:0

Actual device list

./ublk list
dev id 3: nr_hw_queues 1 queue_depth 128 block size 4096 dev_capacity 0
	max rq size 524288 daemon pid 124008 flags 0x42 state LIVE
	ublkc: 235:3 ublkb: 259:0 owner: 0:0
	queue 0: tid 124009 affinity(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 )
	target {"backing_file":"10M","dev_size":10,"direct_io":1,"name":"loop","type":1}

gaurangtapase avatar Feb 21 '25 19:02 gaurangtapase

Hi @ming1 , Thanks for the response. My apologies I didn't make this clear in my request.

Basically, can we create a ublk device from ublksrv and then expect it to be usable by ublklib-rs?

From my simple test (creating a ublkCtrl using new_simple and use dump() to get the ublk device info. It doesn't seem to be working (especially doesn't show the target json data)

rublk doesn't know the json file path for device created by ublksrv, also the json file format may be different between the two applications, so rublk can't deal with the device info part stored in json file, and it has only the device context stored in kernel side.

In reality, either libublksrv(C lib) or libublk-rs(Rust lib) is used, and I guess there isn't such interoperability requirement, or care to share your exact requirement?

Thanks,

ming1 avatar Feb 22 '25 01:02 ming1

Hi, was watching and just chiming in here;

I was hoping there is a standard that different libraries (in whatever language) could agree upon, so that there is some form of interoperability.

In our particular usecase, we have ublk devices being created using ublksrv, but we would like to manage them in our Rust application (which ideally means we could use libublk-rs).

jgrund avatar Feb 24 '25 12:02 jgrund

Hi, was watching and just chiming in here;

I was hoping there is a standard that different libraries (in whatever language) could agree upon, so that there is some form of interoperability.

In our particular usecase, we have ublk devices being created using ublksrv, but we would like to manage them in our Rust application (which ideally means we could use libublk-rs).

Hello,

Can you provide some details about the 'managing' task from Rust lib/app?

Thanks,

ming1 avatar Feb 25 '25 03:02 ming1

Hi, was watching and just chiming in here; I was hoping there is a standard that different libraries (in whatever language) could agree upon, so that there is some form of interoperability. In our particular usecase, we have ublk devices being created using ublksrv, but we would like to manage them in our Rust application (which ideally means we could use libublk-rs).

Hello,

Can you provide some details about the 'managing' task from Rust lib/app?

Thanks,

Basically, from our Rust app, we need to read the target json data of the ublk devices created from ublksrv.

gaurangtapase avatar Feb 25 '25 14:02 gaurangtapase

Basically, from our Rust app, we need to read the target json data of the ublk > devices created from ublksrv.

OK, got it.

Then you needn't libublk-rs for providing the feature, and if you know the json path of the created ublk device, your rust app can read from the file and parse it.

I am thinking how to setup rust ublk's default json directory, and maybe the default can be '/run/ublksrvd', which is used by libublksrv too. Then you can get the json path from the UblkCtrl instance.

Does this way work for you?

Thanks,

ming1 avatar Feb 25 '25 14:02 ming1

Yes, having a normalized directory between the two libs would work.

jgrund avatar Feb 26 '25 17:02 jgrund