Skip to contentSkip to conversation

blockdev: Remove the --setbsz (set blocksize) option which has never worked.

PATCH Applied Richard W.M. Jones 3 participants 8 messages Oct 8, 2013 – Oct 11, 2013 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 blockdev: Remove the --setbsz (set blocksize) option which has never worked.

From: "Richard W.M. Jones" <[email protected]>

This option has never worked. If you try setting the block size on a block device, and then read it using --getbsz, you will see that the block size never changes.

The reason for this is because the block size is specific to the current file descriptor opening the block device, so the change of block size only persists for as long as blockdev has the device open, and is lost once blockdev exits.

Also the block size is not really used anywhere. Filesystems, for example, have their own idea of block size and ignore this setting completely.

(Thanks Masayoshi Mizuma for diagnosing the problem)

---
 bash-completion/blockdev | 7 +------
 disk-utils/blockdev.8    | 2 --
 disk-utils/blockdev.c    | 7 -------
 3 files changed, 1 insertion(+), 15 deletions(-)
bash-completion/blockdev +1 -6
index ce986cb..5889955 100644
@@ -19,7 +19,6 @@ _blockdev_module()
 		--getalignoff
 		--getmaxsect
 		--getbsz
-		--setbsz
 		--getsize64
 		--setra
 		--getra
@@ -29,11 +28,7 @@ _blockdev_module()
 		--rereadpt
 		$DEVS"
 	case $prev in
-		'--setbsz')
-			COMPREPLY=( $(compgen -W "bytes" -- $cur) )
-			return 0
-			;;
-		'--setbsz'|'--setfra')
+		'--setfra')
 			COMPREPLY=( $(compgen -W "sectors" -- $cur) )
 			return 0
 			;;
disk-utils/blockdev.8 +0 -2
index 2b3d64c..6ab4324 100644
@@ -67,8 +67,6 @@ Print sectorsize in bytes - usually 512.
 Get size in 512-byte sectors.
 .IP "\fB\-\-rereadpt\fP"
 Reread partition table
-.IP "\fB\-\-setbsz\fP \fIbytes\fP"
-Set blocksize.
 .IP "\fB\-\-setfra\fP \fIsectors\fP"
 Set filesystem readahead (same like --setra on 2.6 kernels).
 .IP "\fB\-\-setra\fP \fIsectors\fP"
disk-utils/blockdev.c +0 -7
index 4543818..dc02d48 100644
@@ -122,13 +122,6 @@ static const struct bdc bdcms[] =
 		.argval = -1,
 		.help = N_("get blocksize")
 	},{
-		IOCTL_ENTRY(BLKBSZSET),
-		.name = "--setbsz",
-		.argname = "<bytes>",
-		.argtype = ARG_INT,
-		.flags = FL_NORESULT,
-	        .help = N_("set blocksize")
-	},{
 		IOCTL_ENTRY(BLKGETSIZE),
 		.name = "--getsize",
 		.argtype = ARG_ULONG,
Signature · 1 line
1.8.3.1
maintainer Applied
#1 lore raw
Quoted 4 lines · Richard W.M. Jones
 bash-completion/blockdev | 7 +------
 disk-utils/blockdev.8    | 2 --
 disk-utils/blockdev.c    | 7 -------
 3 files changed, 1 insertion(+), 15 deletions(-)

Applied, thanks.

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#2 lore raw
In reply to Richard W.M. Jones
Quoted 71 lines · Richard W.M. Jones

From: "Richard W.M. Jones" <[email protected]>

This option has never worked. If you try setting the block size on a block device, and then read it using --getbsz, you will see that the block size never changes.

The reason for this is because the block size is specific to the current file descriptor opening the block device, so the change of block size only persists for as long as blockdev has the device open, and is lost once blockdev exits.

Also the block size is not really used anywhere. Filesystems, for example, have their own idea of block size and ignore this setting completely.

(Thanks Masayoshi Mizuma for diagnosing the problem)

---
 bash-completion/blockdev | 7 +------
 disk-utils/blockdev.8    | 2 --
 disk-utils/blockdev.c    | 7 -------
 3 files changed, 1 insertion(+), 15 deletions(-)
bash-completion/blockdev +1 -6
index ce986cb..5889955 100644
@@ -19,7 +19,6 @@ _blockdev_module()
 		--getalignoff
 		--getmaxsect
 		--getbsz
-		--setbsz
 		--getsize64
 		--setra
 		--getra
@@ -29,11 +28,7 @@ _blockdev_module()
 		--rereadpt
 		$DEVS"
 	case $prev in
-		'--setbsz')
-			COMPREPLY=( $(compgen -W "bytes" -- $cur) )
-			return 0
-			;;
-		'--setbsz'|'--setfra')
+		'--setfra')
 			COMPREPLY=( $(compgen -W "sectors" -- $cur) )
 			return 0
 			;;
disk-utils/blockdev.8 +0 -2
index 2b3d64c..6ab4324 100644
@@ -67,8 +67,6 @@ Print sectorsize in bytes - usually 512.
 Get size in 512-byte sectors.
 .IP "\fB\-\-rereadpt\fP"
 Reread partition table
-.IP "\fB\-\-setbsz\fP \fIbytes\fP"
-Set blocksize.
 .IP "\fB\-\-setfra\fP \fIsectors\fP"
 Set filesystem readahead (same like --setra on 2.6 kernels).
 .IP "\fB\-\-setra\fP \fIsectors\fP"
disk-utils/blockdev.c +0 -0
index 4543818..dc02d48 100644
@@ -122,13 +122,6 @@ static const struct bdc bdcms[] =
 		.argval = -1,
 		.help = N_("get blocksize")
 	},{

disk-utils/blockdev.c static const struct bdc bdcms[] = · line 127

Quoted 10 lines
disk-utils/blockdev.c +0 -7
-		IOCTL_ENTRY(BLKBSZSET),
-		.name = "--setbsz",
-		.argname = "<bytes>",
-		.argtype = ARG_INT,
-		.flags = FL_NORESULT,
-	        .help = N_("set blocksize")
-	},{
 		IOCTL_ENTRY(BLKGETSIZE),
 		.name = "--getsize",
 		.argtype = ARG_ULONG,

Might one process the adjusted block device in a subshell?

$ (blockdev --setbsz 2048 /dev/stdin; blockdev --getbsz /dev/stdin) < /dev/loop0
2048

cheers,
Pádraig.

#3 lore raw
Quoted 85 lines · Pádraig Brady
Quoted 71 lines · Richard W.M. Jones

From: "Richard W.M. Jones" <[email protected]>

This option has never worked. If you try setting the block size on a block device, and then read it using --getbsz, you will see that the block size never changes.

The reason for this is because the block size is specific to the current file descriptor opening the block device, so the change of block size only persists for as long as blockdev has the device open, and is lost once blockdev exits.

Also the block size is not really used anywhere. Filesystems, for example, have their own idea of block size and ignore this setting completely.

(Thanks Masayoshi Mizuma for diagnosing the problem)

---
 bash-completion/blockdev | 7 +------
 disk-utils/blockdev.8    | 2 --
 disk-utils/blockdev.c    | 7 -------
 3 files changed, 1 insertion(+), 15 deletions(-)
bash-completion/blockdev +1 -6
index ce986cb..5889955 100644
@@ -19,7 +19,6 @@ _blockdev_module()
 		--getalignoff
 		--getmaxsect
 		--getbsz
-		--setbsz
 		--getsize64
 		--setra
 		--getra
@@ -29,11 +28,7 @@ _blockdev_module()
 		--rereadpt
 		$DEVS"
 	case $prev in
-		'--setbsz')
-			COMPREPLY=( $(compgen -W "bytes" -- $cur) )
-			return 0
-			;;
-		'--setbsz'|'--setfra')
+		'--setfra')
 			COMPREPLY=( $(compgen -W "sectors" -- $cur) )
 			return 0
 			;;
disk-utils/blockdev.8 +0 -2
index 2b3d64c..6ab4324 100644
@@ -67,8 +67,6 @@ Print sectorsize in bytes - usually 512.
 Get size in 512-byte sectors.
 .IP "\fB\-\-rereadpt\fP"
 Reread partition table
-.IP "\fB\-\-setbsz\fP \fIbytes\fP"
-Set blocksize.
 .IP "\fB\-\-setfra\fP \fIsectors\fP"
 Set filesystem readahead (same like --setra on 2.6 kernels).
 .IP "\fB\-\-setra\fP \fIsectors\fP"
disk-utils/blockdev.c +0 -0
index 4543818..dc02d48 100644
@@ -122,13 +122,6 @@ static const struct bdc bdcms[] =
 		.argval = -1,
 		.help = N_("get blocksize")
 	},{

disk-utils/blockdev.c static const struct bdc bdcms[] = · line 127

Quoted 10 lines
disk-utils/blockdev.c +0 -7
-		IOCTL_ENTRY(BLKBSZSET),
-		.name = "--setbsz",
-		.argname = "<bytes>",
-		.argtype = ARG_INT,
-		.flags = FL_NORESULT,
-	        .help = N_("set blocksize")
-	},{
 		IOCTL_ENTRY(BLKGETSIZE),
 		.name = "--getsize",
 		.argtype = ARG_ULONG,

Might one process the adjusted block device in a subshell?

Quoted 2 lines
$ (blockdev --setbsz 2048 /dev/stdin; blockdev --getbsz /dev/stdin) < /dev/loop0
2048

Yes .. if that was documented anywhere, if it wasn't so obscure, and if it was useful for anything except changing a handle property that nothing uses.

There's an informative but unfortunately private exchange on the subject in this bug:
https://bugzilla.redhat.com/show_bug.cgi?id=1002825

I have asked if we can make the contents of this bug public.

Rich.

Signature · 4 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top
#4 lore raw
Quoted 93 lines · Richard W.M. Jones
Quoted 85 lines · Pádraig Brady
Quoted 71 lines · Richard W.M. Jones

From: "Richard W.M. Jones" <[email protected]>

This option has never worked. If you try setting the block size on a block device, and then read it using --getbsz, you will see that the block size never changes.

The reason for this is because the block size is specific to the current file descriptor opening the block device, so the change of block size only persists for as long as blockdev has the device open, and is lost once blockdev exits.

Also the block size is not really used anywhere. Filesystems, for example, have their own idea of block size and ignore this setting completely.

(Thanks Masayoshi Mizuma for diagnosing the problem)

---
 bash-completion/blockdev | 7 +------
 disk-utils/blockdev.8    | 2 --
 disk-utils/blockdev.c    | 7 -------
 3 files changed, 1 insertion(+), 15 deletions(-)
bash-completion/blockdev +1 -6
index ce986cb..5889955 100644
@@ -19,7 +19,6 @@ _blockdev_module()
 		--getalignoff
 		--getmaxsect
 		--getbsz
-		--setbsz
 		--getsize64
 		--setra
 		--getra
@@ -29,11 +28,7 @@ _blockdev_module()
 		--rereadpt
 		$DEVS"
 	case $prev in
-		'--setbsz')
-			COMPREPLY=( $(compgen -W "bytes" -- $cur) )
-			return 0
-			;;
-		'--setbsz'|'--setfra')
+		'--setfra')
 			COMPREPLY=( $(compgen -W "sectors" -- $cur) )
 			return 0
 			;;
disk-utils/blockdev.8 +0 -2
index 2b3d64c..6ab4324 100644
@@ -67,8 +67,6 @@ Print sectorsize in bytes - usually 512.
 Get size in 512-byte sectors.
 .IP "\fB\-\-rereadpt\fP"
 Reread partition table
-.IP "\fB\-\-setbsz\fP \fIbytes\fP"
-Set blocksize.
 .IP "\fB\-\-setfra\fP \fIsectors\fP"
 Set filesystem readahead (same like --setra on 2.6 kernels).
 .IP "\fB\-\-setra\fP \fIsectors\fP"
disk-utils/blockdev.c +0 -0
index 4543818..dc02d48 100644
@@ -122,13 +122,6 @@ static const struct bdc bdcms[] =
 		.argval = -1,
 		.help = N_("get blocksize")
 	},{

disk-utils/blockdev.c static const struct bdc bdcms[] = · line 127

Quoted 10 lines
disk-utils/blockdev.c +0 -7
-		IOCTL_ENTRY(BLKBSZSET),
-		.name = "--setbsz",
-		.argname = "<bytes>",
-		.argtype = ARG_INT,
-		.flags = FL_NORESULT,
-	        .help = N_("set blocksize")
-	},{
 		IOCTL_ENTRY(BLKGETSIZE),
 		.name = "--getsize",
 		.argtype = ARG_ULONG,

Might one process the adjusted block device in a subshell?

Quoted 2 lines
$ (blockdev --setbsz 2048 /dev/stdin; blockdev --getbsz /dev/stdin) < /dev/loop0
2048

Yes .. if that was documented anywhere, if it wasn't so obscure, and if it was useful for anything except changing a handle property that nothing uses.

Quoted 7 lines

There's an informative but unfortunately private exchange on the subject in this bug:
https://bugzilla.redhat.com/show_bug.cgi?id=1002825

I have asked if we can make the contents of this bug public.

Rich.

For my own reference, the way I see it,
when accessing block devices Linux uses these block sizes:

physical defined by the hardware device
logical the smallest addressable unit used for the device
file system ditto for the file system

--[gs]etbsz refers the _logical_ block size for the device. Traditionally one had a physical of 512, but a larger logical size of say 4096, with the size determining the standard I/O operations Vs fragmentation tradeoff.

So why might one want to --setbsz?
I agree that would be fairly specialized.
I'm guessing that the logical size default is determined using the device size, maxing out at the page size.
One might want to reduce that (temporarily), for odd sized devices, where you might want to read/write slop at the end of the device?

But for low level access like this, one would probably use direct IO to avoid the page cache (sized) reads/writes anyway.

I searched for uses of --setbz and noticed a couple:
Perf testing:
https://lkml.org/lkml/2003/12/30/81
Functionality testing:
http://www.linux-archive.org/device-mapper-development/699549-blockdev-fix-crash-when-block-size-changed-i-o-issued-simultaneously.html

So I'm not against removing it. If others wanted to leave it in, then it would have to be documented that it was a transient setting.

thanks,
Pádraig.

maintainer
#5 lore raw
Quoted 8 lines · Pádraig Brady

For my own reference, the way I see it,
when accessing block devices Linux uses these block sizes:

physical defined by the hardware device
logical the smallest addressable unit used for the device
file system ditto for the file system

--[gs]etbsz refers the _logical_ block size for the device.

Well, let's be more pedantic ;-)

The disks and raids provides I/O limits:

physical block size (BLKPBSZGET)
logical block size (BLKSSZGET)

but kernel also uses

soft block size BLKBSZGET

this size is never smaller than logical size and (I guess) usually same as PAGE_SIZE. So it's really not *device* logical block size, it's more about the way how kernel uses the device.

Quoted 2 lines

So why might one want to --setbsz?
I agree that would be fairly specialized.

Yes, it's practically useless in tool like blockdev(8).

Quoted 5 lines

I searched for uses of --setbz and noticed a couple:
Perf testing:
https://lkml.org/lkml/2003/12/30/81
Functionality testing:
http://www.linux-archive.org/device-mapper-development/699549-blockdev-fix-crash-when-block-size-changed-i-o-issued-simultaneously.html

Good point (it seems I was too rash to apply Rich's patch;-)

Maybe we can keep --setbsz in the code for testing purpose and for backward compatibility, then all we need is describe the ioctl in the blockdev(8) man page.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#7 lore raw
In reply to Richard W.M. Jones
Quoted 5 lines · Richard W.M. Jones

There's an informative but unfortunately private exchange on the subject in this bug:
https://bugzilla.redhat.com/show_bug.cgi?id=1002825

I have asked if we can make the contents of this bug public.

This bug should be public now.

Rich.

Signature · 4 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine.  Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/
maintainer
#6 lore raw
In reply to Pádraig Brady
Quoted 2 lines · Pádraig Brady

So I'm not against removing it. If others wanted to leave it in, then it would have to be documented that it was a transient setting.

I have reverted Rich's patch and improved --setbsz docs.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com