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

libtcmu: add support for write protect #680

Merged
merged 1 commit into from
Feb 21, 2022

Conversation

liulanzheng
Copy link
Contributor

As discussed in #654, add an api to set write-protect for dev, and set the corresponding parameter when mode sense.

Signed-off-by: liulanzheng [email protected]

@lxbsz
Copy link
Collaborator

lxbsz commented Feb 18, 2022

Do you have any use case for this ?

@liulanzheng
Copy link
Contributor Author

@lxbsz in overlaybd, we output container images as block device through libtcmu for data acceleration. Images, like overlaybd containerd images, and vm images, also iso images, are readonly, it is better to provided a method to mark the device as readonly fundamentally, which is significantly better than executing blockdev --setro command on client.
At first, we use tgtd as the backstore and it has readonly option for target configuration. So i think adding an option for write-protect/readonly is a real need.

@lxbsz
Copy link
Collaborator

lxbsz commented Feb 21, 2022

BTW, which spc or sbc you are referring to for orig_buf[3] and orig_buf[2] ? From the sbc for MODE_SENSE_10 the first 8 bytes are reserved only for the NUMBER OF LOGICAL BLOCKS, and for MODE_SENSE there are 4 bytes.

@lxbsz
Copy link
Collaborator

lxbsz commented Feb 21, 2022

BTW, which spc or sbc you are referring to for orig_buf[3] and orig_buf[2] ? From the sbc for MODE_SENSE_10 the first 8 bytes are reserved only for the NUMBER OF LOGICAL BLOCKS, and for MODE_SENSE there are 4 bytes.

Okay, I misread the docs and I see it.

libtcmu.c Outdated
@@ -1021,6 +1021,16 @@ bool tcmu_dev_get_unmap_enabled(struct tcmu_device *dev)
return dev->unmap_enabled;
}

bool tcmu_dev_set_write_protect_enabled(struct tcmu_device *dev, bool enabled)
Copy link
Collaborator

Choose a reason for hiding this comment

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

s/bool/void/

/data/tcmu-runner/libtcmu.c: In function ‘tcmu_dev_set_write_protect_enabled’:
/data/tcmu-runner/libtcmu.c:1027:1: error: control reaches end of non-void function [-Werror=return-type]
 }
 ^

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sorry, i remember i fixed it, but ... it's fixed now.

@liulanzheng liulanzheng force-pushed the write-protect branch 2 times, most recently from e819707 to d49be68 Compare February 21, 2022 04:12
libtcmu_priv.h Outdated
@@ -55,6 +55,7 @@ struct tcmu_device {
unsigned int write_cache_enabled:1;
unsigned int solid_state_media:1;
unsigned int unmap_enabled:1;
unsigned int write_protect_enabled: 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove the white space before 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

Copy link
Collaborator

@lxbsz lxbsz left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks.

@lxbsz lxbsz merged commit 364ae61 into open-iscsi:master Feb 21, 2022
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