Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tgt_loop: Introduce device offset #89

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

zippy2
Copy link

@zippy2 zippy2 commented Jan 30, 2025

Just like losetup allows skipping first N bytes on the underlying file, let's have something similar for tgt_loop.

The format string in nbd_setup_tgt() lacks pragma for printing
the last argument (send_zc) even though the variable is passed
afterwards.

Signed-off-by: Michal Privoznik <[email protected]>
The aim of ublksrv_json_read_target_ulong_info() is to fetch
value corresponding to given key from JSON and return it in its
last argument. But the last argument is of type long which
contradicts not only the function name but also set function
(ublksrv_json_write_target_ulong_info()). Switch the argument
type to unsigned long.

Signed-off-by: Michal Privoznik <[email protected]>
The intended way to store additional data associated with a
target is via tgt_data pointer. So far, global variables are used
which works, but gives bad example for anybody taking inspiration
from our code.

This also fixes a bug, where @block_device wasn't set during
recovery, only in loop_init_tgt().

Signed-off-by: Michal Privoznik <[email protected]>
The aim of tgt_loop is to mimic losetup. Well, losetup allow
users to move the start of loopback device given amount of bytes
(-o/--offset arguments). Provide missing implementation.

Signed-off-by: Michal Privoznik <[email protected]>
@@ -199,6 +226,17 @@ static int loop_init_tgt(struct ublksrv_dev *dev, int type, int argc, char
buffered_io = 1;
}

if (bytes > 0) {
unsigned long long offset_bytes = offset * (1 << p.basic.physical_bs_shift);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the helper message of offset skips first NUM sectors on backing file, here we should figure out offset_bytes via offset * 512, which is applied in IO code path too.

Otherwise, this PR looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants