Skip to contentSkip to conversation

subvolume list as user?

DISCUSSION Ulli Horlacher 3 participants 6 messages Sep 16, 2017 – Sep 17, 2017 Btrfs file system

lore
Share & tools
lore
#0 lore raw

Every user can create subvolumes (and root cannot prevent it!). But how can a user list these subvolumes?

tux@xerus:/test/tux: btrfs subvolume create test
Create subvolume './test'

tux@xerus:/test/tux: btrfs subvolume list .
ERROR: can't perform the search - Operation not permitted

Signature · 6 lines
Ullrich Horlacher              Server und Virtualisierung
Rechenzentrum TIK         
Universitaet Stuttgart         E-Mail: [email protected]
Allmandring 30a                Tel:    ++49-711-68565868
70569 Stuttgart (Germany)      WWW:    http://www.tik.uni-stuttgart.de
REF:<[email protected]>
#1 lore raw
Quoted 7 lines · Ulli Horlacher

Every user can create subvolumes (and root cannot prevent it!). But how can a user list these subvolumes?

tux@xerus:/test/tux: btrfs subvolume create test
Create subvolume './test'

From your other posts I don't quickly get if you actually do want to

have this possible, or accept that it's currently like that and try to do damage control by having users also remove their things again.

Actually, if you don't want this I think it's quite easily to patch your kernel with one or two lines of code to disallow it.

Quoted 2 lines

tux@xerus:/test/tux: btrfs subvolume list .
ERROR: can't perform the search - Operation not permitted

Yes, because the SEARCH ioctl only allows root to directly query any of the filesystem metadata from kernel memory. subvolume list uses this SEARCH ioctl to find it's info.

Signature · 1 line
Hans van Kranenburg
#2 lore raw
Quoted 14 lines · Hans van Kranenburg
Quoted 5 lines · Ulli Horlacher

Every user can create subvolumes (and root cannot prevent it!). But how can a user list these subvolumes?

tux@xerus:/test/tux: btrfs subvolume create test
Create subvolume './test'

From your other posts I don't quickly get if you actually do want to have this possible, or accept that it's currently like that and try to do damage control by having users also remove their things again.

Actually, if you don't want this I think it's quite easily to patch your kernel with one or two lines of code to disallow it.

Quoted 6 lines
Quoted 2 lines

tux@xerus:/test/tux: btrfs subvolume list .
ERROR: can't perform the search - Operation not permitted

Yes, because the SEARCH ioctl only allows root to directly query any of the filesystem metadata from kernel memory. subvolume list uses this SEARCH ioctl to find it's info.

its! Argh! D:

Signature · 1 line
Hans van Kranenburg
#3 lore raw
In reply to Hans van Kranenburg
Quoted 11 lines · Hans van Kranenburg
Quoted 5 lines · Ulli Horlacher

Every user can create subvolumes (and root cannot prevent it!). But how can a user list these subvolumes?

tux@xerus:/test/tux: btrfs subvolume create test
Create subvolume './test'

From your other posts I don't quickly get if you actually do want to have this possible, or accept that it's currently like that and try to do damage control by having users also remove their things again.

I want both, country AND western :-)

Without joking:
I just want to learn more about btrfs and I have various use cases to handle.

Different use cases need different actions.

Quoted 2 lines

Actually, if you don't want this I think it's quite easily to patch your kernel with one or two lines of code to disallow it.

Kernel patching is a no-go for me. My boss does not allow it. No discussion possible on this topic.

Quoted 6 lines
Quoted 2 lines

tux@xerus:/test/tux: btrfs subvolume list .
ERROR: can't perform the search - Operation not permitted

Yes, because the SEARCH ioctl only allows root to directly query any of the filesystem metadata from kernel memory. subvolume list uses this SEARCH ioctl to find it's info.

This is the explantion why it does not work, but it does not help me. I still have the problem: how can a user get a list of his subvolumes? He may created them some time ago and forget it. He now wants to have a list of them.

Signature · 6 lines
Ullrich Horlacher              Server und Virtualisierung
Rechenzentrum TIK         
Universitaet Stuttgart         E-Mail: [email protected]
Allmandring 30a                Tel:    ++49-711-68565868
70569 Stuttgart (Germany)      WWW:    http://www.tik.uni-stuttgart.de/
REF:<[email protected]>
#4 lore raw
Quoted 32 lines · Ulli Horlacher
Quoted 11 lines · Hans van Kranenburg
Quoted 5 lines · Ulli Horlacher

Every user can create subvolumes (and root cannot prevent it!). But how can a user list these subvolumes?

tux@xerus:/test/tux: btrfs subvolume create test
Create subvolume './test'

From your other posts I don't quickly get if you actually do want to have this possible, or accept that it's currently like that and try to do damage control by having users also remove their things again.

I want both, country AND western :-)

Without joking:
I just want to learn more about btrfs and I have various use cases to handle.

Different use cases need different actions.

Quoted 2 lines

Actually, if you don't want this I think it's quite easily to patch your kernel with one or two lines of code to disallow it.

Kernel patching is a no-go for me. My boss does not allow it. No discussion possible on this topic.

Quoted 3 lines
Quoted 2 lines

tux@xerus:/test/tux: btrfs subvolume list .
ERROR: can't perform the search - Operation not permitted

Quoted 8 lines
Quoted 3 lines

Yes, because the SEARCH ioctl only allows root to directly query any of the filesystem metadata from kernel memory. subvolume list uses this SEARCH ioctl to find it's info.

This is the explantion why it does not work, but it does not help me. I still have the problem: how can a user get a list of his subvolumes? He may created them some time ago and forget it. He now wants to have a list of them.

Far to be perfect, but this could help

find / -inum 256 2>/dev/null

each subvolume has inode number 256

BR
G.Baroncelli

Signature · 2 lines
gpg @keyserver.linux.it: Goffredo Baroncelli <kreijackATinwind.it>
Key fingerprint BBF5 1610 0B64 DAC6 5F7D  17B2 0EDA 9B37 8B82 E0B5
#5 lore raw
Quoted 8 lines · Goffredo Baroncelli
Quoted 2 lines

how can a user get a list of his subvolumes? He may created them some time ago and forget it. He now wants to have a list of them.

Far to be perfect, but this could help

find / -inum 256 2>/dev/null

each subvolume has inode number 256

But non-btrfs filesystems can also have an inode 256! And it is terrible slow and inefficent.
Ok, I will add a sudo wrapper for my btrfs_subvolume_list :

#!/usr/bin/perl -w

$mounts = '/proc/mounts';
open $mounts,$mounts or die "$0: cannot open $mounts - $!\n"; while (<$mounts>) {

  if (m:^(/\S+) (/\S*) btrfs:) {
    push @bfs,$2;

}
}
close $mounts;
if (@bfs) {
@bfs = sort @bfs;
} else {
die "$0: no mounted btrfs filesystems\n";
}

@sv = ();
foreach my $fs (@bfs) {
push @sv,"$fs\n";
open $fs,"btrfs subvolume list '$fs'|" or next;;

  while (<$fs>) {
    chomp;
    s:.* \d+ path :$fs/:;
    push @sv,"$_\n" if -d;

}
close $fs;
}

print sort @sv;

Signature · 6 lines
Ullrich Horlacher              Server und Virtualisierung
Rechenzentrum TIK         
Universitaet Stuttgart         E-Mail: [email protected]
Allmandring 30a                Tel:    ++49-711-68565868
70569 Stuttgart (Germany)      WWW:    http://www.tik.uni-stuttgart.de/
REF:<[email protected]>