Re: kernel BUG at fs/btrfs/relocation.c:1062

2013-12-20 Thread Tomasz Chmielewski
On Sat, 21 Dec 2013 01:11:00 +0800
Shilong Wang  wrote:

> ok, It seems that your filesystem is not in consistency anymore.
> To confirm your filesystem status, you can try to run btrfsck to
> check if there is something wrong.
> 
> To get a stable fs now, you can try to mount btrfs with option
> skip_balance and recovery, recovery options try to get a previous
> good tree root which might help you
> get a stable fs.

Unfortunately even after using these mount options it breaks as before,
as soon as I remove snapshots, or even copy some data in with rsync.

Oh well, at least I have read only access...


-- 
Tomasz Chmielewski
http://wpkg.org
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3] Btrfs: fix tree mod logging

2013-12-20 Thread Holger Hoffstätte
On Fri, 20 Dec 2013 23:31:44 +, Filipe David Manana wrote:

> On Fri, Dec 20, 2013 at 11:19 PM, Holger Hoffstätte
>  wrote:
>> On Fri, 20 Dec 2013 15:17:46 +, Filipe David Borba Manana wrote:
>>
>> I applied this to 3.12.6 and was rewarded with:
>>
>> *fs/btrfs/ctree.c: In function 'tree_mod_log_set_node_key':
> 
> Did you apply first the patch titled "Btrfs: return immediately if tree
> log mod is not necessary" ?

No, of course not. =)

Looking at that one makes things clear and applying it first fixed it. 
Everything built fine and seems to work, no spontaneous combustions yet.

Thanks!

-h

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3] Btrfs: fix tree mod logging

2013-12-20 Thread Filipe David Manana
On Fri, Dec 20, 2013 at 11:19 PM, Holger Hoffstätte
 wrote:
> On Fri, 20 Dec 2013 15:17:46 +, Filipe David Borba Manana wrote:
>
> [..patch..]
>
> I applied this to 3.12.6 and was rewarded with:
>
> *fs/btrfs/ctree.c: In function 'tree_mod_log_set_node_key':
> *fs/btrfs/ctree.c:924:2: error: implicit declaration of function
> '__tree_mod_log_insert_key' [-Werror=implicit-function-declaration]
> *  ret = __tree_mod_log_insert_key(fs_info, eb, slot,
> *  ^
> *cc1: some warnings being treated as errors
> *scripts/Makefile.build:308: recipe for target 'fs/btrfs/ctree.o' failed
>
> Said function prototype is nowhere to be found, only the regular non-
> scoped function. Did you just miss this call? Changing the call to the
> remaining tree_mod_log_insert_key() looks like what was intended and
> compiles, but I wanted to check before I burn the house down. :)

Did you apply first the patch titled "Btrfs: return immediately if
tree log mod is not necessary" ?
It depends on that one, and both are targeted against btrfs-next
repository from Josef. Didn't try 3.12.* at all.

Thanks


>
> -h
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html



-- 
Filipe David Manana,

"Reasonable men adapt themselves to the world.
 Unreasonable men adapt the world to themselves.
 That's why all progress depends on unreasonable men."
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v3] Btrfs: fix tree mod logging

2013-12-20 Thread Holger Hoffstätte
On Fri, 20 Dec 2013 15:17:46 +, Filipe David Borba Manana wrote:

[..patch..]

I applied this to 3.12.6 and was rewarded with:

*fs/btrfs/ctree.c: In function 'tree_mod_log_set_node_key':
*fs/btrfs/ctree.c:924:2: error: implicit declaration of function 
'__tree_mod_log_insert_key' [-Werror=implicit-function-declaration]
*  ret = __tree_mod_log_insert_key(fs_info, eb, slot,
*  ^
*cc1: some warnings being treated as errors
*scripts/Makefile.build:308: recipe for target 'fs/btrfs/ctree.o' failed

Said function prototype is nowhere to be found, only the regular non-
scoped function. Did you just miss this call? Changing the call to the 
remaining tree_mod_log_insert_key() looks like what was intended and 
compiles, but I wanted to check before I burn the house down. :)

-h

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: btrfs on bcache

2013-12-20 Thread Henry de Valence
On Thu, Dec 19, 2013 at 2:04 PM, Fábio Pfeifer  wrote:
> Any update on this?
>
> I have here exactly the same issue. Kernel 3.12.5-1-ARCH, backing
> device 500 GB IDE, cache 24 GB SSD => /dev/bcache0
> On /dev/bcache I also have 2 subvolumes, / and /home. I get lots of
> messages in dmesg:

I also have this issue.

Also, this afternoon I experienced data corruption on my btrfs device
(checksum errors), which might or might not be related. I don't really
know how to determine the cause, but if anyone has suggestions they'd
be appreciated.

Cheers,
Henry de Valence
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: kernel BUG at fs/btrfs/relocation.c:1062

2013-12-20 Thread Shilong Wang
2013/12/21 Tomasz Chmielewski :
> On Sat, 21 Dec 2013 00:07:19 +0800
> Shilong Wang  wrote:
>
>> 2013/12/20 Tomasz Chmielewski :
>> > -o  skip_balance - didn't know this.
>> >
>> > Actually, I was able to "skip" the balance, sort of, with this:
>> >
>> > mount /mnt/btrfs ; btrfs fi balance cancel /mnt/btrfs
>>
>> From your previous email, i suspend your filesystem is nearly fully.
>> "mount -o skip_balance" will avoid balance continuing while use btrfs
>> balance cancel still
>> can not avoid balance totally, so i recommend you use skip_balance
>> option when remounting.
>
> My other thread a few days ago ("no space left, metadata usage almost
> full?"), if that's what you're referring to, was about a different
> filesystem.
>
> This one should have enough free space left:
>
> # btrfs fi
> show /mnt/lxc1 Label: lxc1  uuid: 8d08ad6d-4543-4fe5-8b1b-640dc1423d41
> Total devices 2 FS bytes used 2.02TiB
> devid1 size 2.62TiB used 2.02TiB path /dev/sda5
> devid2 size 2.62TiB used 2.02TiB path /dev/sdb5
>
> Btrfs v3.12
>
> # btrfs fi df /mnt/lxc1
> Data, RAID1: total=1.97TiB, used=1.97TiB
> System, RAID1: total=32.00MiB, used=300.00KiB
> Metadata, RAID1: total=50.00GiB, used=49.21GiB
>
>
> I've tried using skip_balance - it mounted, but breaks soon after I try
> to remove any snapshot.
>

ok, It seems that your filesystem is not in consistency anymore.
To confirm your filesystem status, you can try to run btrfsck to check if there
is something wrong.

To get a stable fs now, you can try to mount btrfs with option skip_balance and
recovery, recovery options try to get a previous good tree root which
might help you
get a stable fs.


>
> --
> Tomasz Chmielewski
> http://wpkg.org
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: kernel BUG at fs/btrfs/relocation.c:1062

2013-12-20 Thread Tomasz Chmielewski
On Sat, 21 Dec 2013 00:07:19 +0800
Shilong Wang  wrote:

> 2013/12/20 Tomasz Chmielewski :
> > -o  skip_balance - didn't know this.
> >
> > Actually, I was able to "skip" the balance, sort of, with this:
> >
> > mount /mnt/btrfs ; btrfs fi balance cancel /mnt/btrfs
> 
> From your previous email, i suspend your filesystem is nearly fully.
> "mount -o skip_balance" will avoid balance continuing while use btrfs
> balance cancel still
> can not avoid balance totally, so i recommend you use skip_balance
> option when remounting.

My other thread a few days ago ("no space left, metadata usage almost
full?"), if that's what you're referring to, was about a different
filesystem.

This one should have enough free space left:

# btrfs fi
show /mnt/lxc1 Label: lxc1  uuid: 8d08ad6d-4543-4fe5-8b1b-640dc1423d41
Total devices 2 FS bytes used 2.02TiB
devid1 size 2.62TiB used 2.02TiB path /dev/sda5
devid2 size 2.62TiB used 2.02TiB path /dev/sdb5

Btrfs v3.12

# btrfs fi df /mnt/lxc1
Data, RAID1: total=1.97TiB, used=1.97TiB
System, RAID1: total=32.00MiB, used=300.00KiB
Metadata, RAID1: total=50.00GiB, used=49.21GiB


I've tried using skip_balance - it mounted, but breaks soon after I try
to remove any snapshot.


-- 
Tomasz Chmielewski
http://wpkg.org
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: kernel BUG at fs/btrfs/relocation.c:1062

2013-12-20 Thread Shilong Wang
2013/12/20 Tomasz Chmielewski :
> -o  skip_balance - didn't know this.
>
> Actually, I was able to "skip" the balance, sort of, with this:
>
> mount /mnt/btrfs ; btrfs fi balance cancel /mnt/btrfs

>From your previous email, i suspend your filesystem is nearly fully.
"mount -o skip_balance" will avoid balance continuing while use btrfs
balance cancel still
can not avoid balance totally, so i recommend you use skip_balance
option when remounting.


>
>
> However, the fs is extremely unstable (will remount read only quite
> fast, i.e. if I start removing snapshot).
>
>
> I'm trying to run btrfsck without the --repair option to see if it
> shows anything interesting.
>

I'd like you not to use btrfsck --repair, it is a little dangerous anyway.
If you still want to try, just use btrfsck is ok to check if your
filesystem is consistent.

Or you can remount with option degraded, recovery(maybe help you  to
make filesystem stable
at least).

Thanks,
Wang

>
> --
> Tomasz Chmielewski
> http://wpkg.org
>
>
> On Fri, 20 Dec 2013 23:52:08 +0800
> Shilong Wang  wrote:
>
>> Hello Tomasz,
>>
>> There should be some bugs flying on, unitil now, you can try to
>> remount: something like:
>>
>> # mount  /dev/sda /mnt -o  skip_balance
>>
>> It will skip unfinshed balance, hopley it can help you before we give
>> a bug fix.
>>
>> Thanks,
>> Wang
>> 2013/12/20 Tomasz Chmielewski :
>> > On Thu, 19 Dec 2013 22:07:37 +0900
>> > Tomasz Chmielewski  wrote:
>> >
>> >> If it matters, I had to hard reboot after that bug; the balance
>> >> continued after the system booted again and I got this a while
>> >> later (filesystem was remounted read only):
>> >
>> > Actually, looks like the fs is quite hosed now :(
>> >
>> > If I want to do an operation like removing a snapshot (btrfs sub
>> > del ...), the command returns, there is IO for a few minutes, but
>> > then, the kernel complains and fs is remounted readonly:
>> >
>> > [ 5111.773900] BTRFS debug (device sdb5): run_one_delayed_ref
>> > returned -17 [ 5111.773902] [ cut here ]
>> > [ 5111.773957] WARNING: CPU: 0 PID: 15042 at fs/btrfs/super.c:254
>> > __btrfs_abort_transaction+0x4d/0xff [btrfs]() [ 5111.774047] btrfs:
>> > Transaction aborted (error -17) [ 5111.774048] Modules linked in:
>> > ipt_MASQUERADE iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4
>> > nf_nat_ipv4 nf_nat nf_conntrack ip_tables x_tables cpufreq_ondemand
>> > cpufreq_conservative cpufreq_powersave cpufreq_stats bridge stp llc
>> > ipv6 btrfs xor raid6_pq zlib_deflate loop pcspkr button video
>> > ehci_pci ehci_hcd acpi_cpufreq i2c_i801 i2c_core lpc_ich mfd_core
>> > ext4 crc16 jbd2 mbcache raid1 sg sd_mod ahci libahci libata
>> > scsi_mod r8169 mii [ 5111.774355] CPU: 0 PID: 15042 Comm:
>> > btrfs-transacti Tainted: GW3.13.0-rc4 #1 [ 5111.774443]
>> > Hardware name: System manufacturer System Product Name/P8H77-M PRO,
>> > BIOS 1101 02/04/2013 [ 5111.774533]  0009
>> > 8800374ddc48 8138a37d 0006 [ 5111.774622]
>> > 8800374ddc98 8800374ddc88 810370a9 8800374ddd80
>> > [ 5111.774711]  a020d524 ffef 8807ead7d800
>> > 8807ff0cc8c0 [ 5111.774800] Call Trace: [ 5111.774846]
>> > [] dump_stack+0x46/0x58 [ 5111.774894]
>> > [] warn_slowpath_common+0x77/0x91 [ 5111.774944]
>> > [] ? __btrfs_abort_transaction+0x4d/0xff [btrfs]
>> > [ 5111.775032]  [] warn_slowpath_fmt+0x41/0x43
>> > [ 5111.775081]  []
>> > __btrfs_abort_transaction+0x4d/0xff [btrfs] [ 5111.775135]
>> > [] btrfs_run_delayed_refs+0x253/0x46f [btrfs]
>> > [ 5111.775189]  []
>> > btrfs_commit_transaction+0x36d/0x7df [btrfs] [ 5111.775281]
>> > [] transaction_kthread+0xef/0x1c2 [btrfs]
>> > [ 5111.775333]  [] ? open_ctree+0x1ac7/0x1ac7
>> > [btrfs] [ 5111.775382]  [] kthread+0xcd/0xd5
>> > [ 5111.775428]  [] ?
>> > kthread_freezable_should_stop+0x43/0x43 [ 5111.775477]
>> > [] ret_from_fork+0x7c/0xb0 [ 5111.775524]
>> > [] ? kthread_freezable_should_stop+0x43/0x43
>> > [ 5111.775572] ---[ end trace b552aca9a0cff3cb ]--- [ 5111.775618]
>> > BTRFS error (device sdb5) in btrfs_run_delayed_refs:2730: errno=-17
>> > Object already exists [ 5111.775707] BTRFS info (device sdb5):
>> > forced readonly [ 5111.775754] BTRFS warning (device sdb5):
>> > Skipping commit of aborted transaction. [ 5111.775841] BTRFS error
>> > (device sdb5) in cleanup_transaction:1553: errno=-17 Object already
>> > exists
>> >
>> >
>> >
>> > If I run balance (after unmounting and mounting the filesystem), it
>> > ends in a similar way:
>> >
>> > [ 5927.338989] btrfs: relocating block group 4647284637696 flags 17
>> > [ 6184.333629] btrfs: found 983 extents
>> > [ 6269.512577] BTRFS debug (device sdb5): run_one_delayed_ref
>> > returned -17 [ 6269.512579] [ cut here ]
>> > [ 6269.512636] WARNING: CPU: 7 PID: 17836 at fs/btrfs/super.c:254
>> > __btrfs_abort_transaction+0x4d/0xff [btrfs]() [ 6269.512727] btrfs:
>> > Transaction aborted (error -17) [ 6269.51

Re: kernel BUG at fs/btrfs/relocation.c:1062

2013-12-20 Thread Tomasz Chmielewski
-o  skip_balance - didn't know this.

Actually, I was able to "skip" the balance, sort of, with this:

mount /mnt/btrfs ; btrfs fi balance cancel /mnt/btrfs


However, the fs is extremely unstable (will remount read only quite
fast, i.e. if I start removing snapshot).


I'm trying to run btrfsck without the --repair option to see if it
shows anything interesting.


-- 
Tomasz Chmielewski
http://wpkg.org


On Fri, 20 Dec 2013 23:52:08 +0800
Shilong Wang  wrote:

> Hello Tomasz,
> 
> There should be some bugs flying on, unitil now, you can try to
> remount: something like:
> 
> # mount  /dev/sda /mnt -o  skip_balance
> 
> It will skip unfinshed balance, hopley it can help you before we give
> a bug fix.
> 
> Thanks,
> Wang
> 2013/12/20 Tomasz Chmielewski :
> > On Thu, 19 Dec 2013 22:07:37 +0900
> > Tomasz Chmielewski  wrote:
> >
> >> If it matters, I had to hard reboot after that bug; the balance
> >> continued after the system booted again and I got this a while
> >> later (filesystem was remounted read only):
> >
> > Actually, looks like the fs is quite hosed now :(
> >
> > If I want to do an operation like removing a snapshot (btrfs sub
> > del ...), the command returns, there is IO for a few minutes, but
> > then, the kernel complains and fs is remounted readonly:
> >
> > [ 5111.773900] BTRFS debug (device sdb5): run_one_delayed_ref
> > returned -17 [ 5111.773902] [ cut here ]
> > [ 5111.773957] WARNING: CPU: 0 PID: 15042 at fs/btrfs/super.c:254
> > __btrfs_abort_transaction+0x4d/0xff [btrfs]() [ 5111.774047] btrfs:
> > Transaction aborted (error -17) [ 5111.774048] Modules linked in:
> > ipt_MASQUERADE iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4
> > nf_nat_ipv4 nf_nat nf_conntrack ip_tables x_tables cpufreq_ondemand
> > cpufreq_conservative cpufreq_powersave cpufreq_stats bridge stp llc
> > ipv6 btrfs xor raid6_pq zlib_deflate loop pcspkr button video
> > ehci_pci ehci_hcd acpi_cpufreq i2c_i801 i2c_core lpc_ich mfd_core
> > ext4 crc16 jbd2 mbcache raid1 sg sd_mod ahci libahci libata
> > scsi_mod r8169 mii [ 5111.774355] CPU: 0 PID: 15042 Comm:
> > btrfs-transacti Tainted: GW3.13.0-rc4 #1 [ 5111.774443]
> > Hardware name: System manufacturer System Product Name/P8H77-M PRO,
> > BIOS 1101 02/04/2013 [ 5111.774533]  0009
> > 8800374ddc48 8138a37d 0006 [ 5111.774622]
> > 8800374ddc98 8800374ddc88 810370a9 8800374ddd80
> > [ 5111.774711]  a020d524 ffef 8807ead7d800
> > 8807ff0cc8c0 [ 5111.774800] Call Trace: [ 5111.774846]
> > [] dump_stack+0x46/0x58 [ 5111.774894]
> > [] warn_slowpath_common+0x77/0x91 [ 5111.774944]
> > [] ? __btrfs_abort_transaction+0x4d/0xff [btrfs]
> > [ 5111.775032]  [] warn_slowpath_fmt+0x41/0x43
> > [ 5111.775081]  []
> > __btrfs_abort_transaction+0x4d/0xff [btrfs] [ 5111.775135]
> > [] btrfs_run_delayed_refs+0x253/0x46f [btrfs]
> > [ 5111.775189]  []
> > btrfs_commit_transaction+0x36d/0x7df [btrfs] [ 5111.775281]
> > [] transaction_kthread+0xef/0x1c2 [btrfs]
> > [ 5111.775333]  [] ? open_ctree+0x1ac7/0x1ac7
> > [btrfs] [ 5111.775382]  [] kthread+0xcd/0xd5
> > [ 5111.775428]  [] ?
> > kthread_freezable_should_stop+0x43/0x43 [ 5111.775477]
> > [] ret_from_fork+0x7c/0xb0 [ 5111.775524]
> > [] ? kthread_freezable_should_stop+0x43/0x43
> > [ 5111.775572] ---[ end trace b552aca9a0cff3cb ]--- [ 5111.775618]
> > BTRFS error (device sdb5) in btrfs_run_delayed_refs:2730: errno=-17
> > Object already exists [ 5111.775707] BTRFS info (device sdb5):
> > forced readonly [ 5111.775754] BTRFS warning (device sdb5):
> > Skipping commit of aborted transaction. [ 5111.775841] BTRFS error
> > (device sdb5) in cleanup_transaction:1553: errno=-17 Object already
> > exists
> >
> >
> >
> > If I run balance (after unmounting and mounting the filesystem), it
> > ends in a similar way:
> >
> > [ 5927.338989] btrfs: relocating block group 4647284637696 flags 17
> > [ 6184.333629] btrfs: found 983 extents
> > [ 6269.512577] BTRFS debug (device sdb5): run_one_delayed_ref
> > returned -17 [ 6269.512579] [ cut here ]
> > [ 6269.512636] WARNING: CPU: 7 PID: 17836 at fs/btrfs/super.c:254
> > __btrfs_abort_transaction+0x4d/0xff [btrfs]() [ 6269.512727] btrfs:
> > Transaction aborted (error -17) [ 6269.512727] Modules linked in:
> > ipt_MASQUERADE iptable_nat nf_conntrack_ipv4 nf_defrag_ipv4
> > nf_nat_ipv4 nf_nat nf_conntrack ip_tables x_tables cpufreq_ondemand
> > cpufreq_conservative cpufreq_powersave cpufreq_stats bridge stp llc
> > ipv6 btrfs xor raid6_pq zlib_deflate loop pcspkr button video
> > ehci_pci ehci_hcd acpi_cpufreq i2c_i801 i2c_core lpc_ich mfd_core
> > ext4 crc16 jbd2 mbcache raid1 sg sd_mod ahci libahci libata
> > scsi_mod r8169 mii [ 6269.513036] CPU: 7 PID: 17836 Comm:
> > btrfs-transacti Tainted: GW3.13.0-rc4 #1 [ 6269.513124]
> > Hardware name: System manufacturer System Product Name/P8H77-M PRO,
> > BIOS 1101 02/04/2013 [ 6269.513214]  0

Re: btrfs on bcache

2013-12-20 Thread Chris Mason
On Fri, 2013-12-20 at 10:42 -0200, Fábio Pfeifer wrote:
> Hello,
> 
> I put the "WARN_ON(1);" after the printk lines (incomplete page read
> and incomplete page write) in extent_io.c.
> 
> here some call traces:
> 
> [   19.509497] incomplete page read in btrfs with offset 2560 and length 1536
> [   19.509500] [ cut here ]
> [   19.509528] WARNING: CPU: 2 PID: 220 at fs/btrfs/extent_io.c:2441
> end_bio_extent_readpage+0x788/0xc20 [btrfs]()
> [   19.509530] Modules linked in: cdc_acm fuse iTCO_wdt
> iTCO_vendor_support snd_hda_codec_analog coretemp kvm_intel kvm raid1
> ext4 crc16 md_mod mbcache jbd2 microcode nvidia(PO) psmouse pcspkr
> evdev serio_raw i2c_i801 lpc_ich i2c_core snd_hda_intel sky2 skge
> i82975x_edac button asus_atk0110 snd_hda_codec snd_hwdep shpchp
> snd_pcm snd_page_alloc snd_timer acpi_cpufreq snd edac_core soundcore
> processor vboxdrv(O) sr_mod cdrom ata_generic pata_acpi hid_generic
> usbhid hid usb_storage sd_mod pata_marvell firewire_ohci uhci_hcd ahci
> ehci_pci firewire_core ata_piix libahci crc_itu_t ehci_hcd libata
> scsi_mod usbcore usb_common btrfs crc32c libcrc32c xor raid6_pq bcache
> [   19.509578] CPU: 2 PID: 220 Comm: btrfs-endio-met Tainted: P
> W  O 3.12.5-1-ARCH #1
> [   19.509580] Hardware name: System manufacturer System Product
> Name/P5WDG2 WS Pro, BIOS 090503/06/2008
> [   19.509581]  0009 880231a63cb0 814ee37b
> 
> [   19.509585]  880231a63ce8 81062bcd ea00085eaec0
> 
> [   19.509587]  8802320cc9c0  880233b0e000
> 880231a63cf8
> [   19.509590] Call Trace:
> [   19.509596]  [] dump_stack+0x54/0x8d
> [   19.509601]  [] warn_slowpath_common+0x7d/0xa0
> [   19.509603]  [] warn_slowpath_null+0x1a/0x20
> [   19.509614]  [] end_bio_extent_readpage+0x788/0xc20 
> [btrfs]

This should mean that bcache is either failing to read some blocks
properly or is fiddling with the bv_len/bv_offset fields.

Could someone from bcache comment?

-chris

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: kernel BUG at fs/btrfs/relocation.c:1062

2013-12-20 Thread Shilong Wang
Hello Tomasz,

There should be some bugs flying on, unitil now, you can try to remount:
something like:

# mount  /dev/sda /mnt -o  skip_balance

It will skip unfinshed balance, hopley it can help you before we give a bug fix.

Thanks,
Wang
2013/12/20 Tomasz Chmielewski :
> On Thu, 19 Dec 2013 22:07:37 +0900
> Tomasz Chmielewski  wrote:
>
>> If it matters, I had to hard reboot after that bug; the balance
>> continued after the system booted again and I got this a while later
>> (filesystem was remounted read only):
>
> Actually, looks like the fs is quite hosed now :(
>
> If I want to do an operation like removing a snapshot (btrfs sub
> del ...), the command returns, there is IO for a few minutes, but then, the
> kernel complains and fs is remounted readonly:
>
> [ 5111.773900] BTRFS debug (device sdb5): run_one_delayed_ref returned -17
> [ 5111.773902] [ cut here ]
> [ 5111.773957] WARNING: CPU: 0 PID: 15042 at fs/btrfs/super.c:254 
> __btrfs_abort_transaction+0x4d/0xff [btrfs]()
> [ 5111.774047] btrfs: Transaction aborted (error -17)
> [ 5111.774048] Modules linked in: ipt_MASQUERADE iptable_nat 
> nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack ip_tables 
> x_tables cpufreq_ondemand cpufreq_conservative cpufreq_powersave 
> cpufreq_stats bridge stp llc ipv6 btrfs xor raid6_pq zlib_deflate loop pcspkr 
> button video ehci_pci ehci_hcd acpi_cpufreq i2c_i801 i2c_core lpc_ich 
> mfd_core ext4 crc16 jbd2 mbcache raid1 sg sd_mod ahci libahci libata scsi_mod 
> r8169 mii
> [ 5111.774355] CPU: 0 PID: 15042 Comm: btrfs-transacti Tainted: GW
> 3.13.0-rc4 #1
> [ 5111.774443] Hardware name: System manufacturer System Product Name/P8H77-M 
> PRO, BIOS 1101 02/04/2013
> [ 5111.774533]  0009 8800374ddc48 8138a37d 
> 0006
> [ 5111.774622]  8800374ddc98 8800374ddc88 810370a9 
> 8800374ddd80
> [ 5111.774711]  a020d524 ffef 8807ead7d800 
> 8807ff0cc8c0
> [ 5111.774800] Call Trace:
> [ 5111.774846]  [] dump_stack+0x46/0x58
> [ 5111.774894]  [] warn_slowpath_common+0x77/0x91
> [ 5111.774944]  [] ? __btrfs_abort_transaction+0x4d/0xff 
> [btrfs]
> [ 5111.775032]  [] warn_slowpath_fmt+0x41/0x43
> [ 5111.775081]  [] __btrfs_abort_transaction+0x4d/0xff 
> [btrfs]
> [ 5111.775135]  [] btrfs_run_delayed_refs+0x253/0x46f 
> [btrfs]
> [ 5111.775189]  [] btrfs_commit_transaction+0x36d/0x7df 
> [btrfs]
> [ 5111.775281]  [] transaction_kthread+0xef/0x1c2 [btrfs]
> [ 5111.775333]  [] ? open_ctree+0x1ac7/0x1ac7 [btrfs]
> [ 5111.775382]  [] kthread+0xcd/0xd5
> [ 5111.775428]  [] ? kthread_freezable_should_stop+0x43/0x43
> [ 5111.775477]  [] ret_from_fork+0x7c/0xb0
> [ 5111.775524]  [] ? kthread_freezable_should_stop+0x43/0x43
> [ 5111.775572] ---[ end trace b552aca9a0cff3cb ]---
> [ 5111.775618] BTRFS error (device sdb5) in btrfs_run_delayed_refs:2730: 
> errno=-17 Object already exists
> [ 5111.775707] BTRFS info (device sdb5): forced readonly
> [ 5111.775754] BTRFS warning (device sdb5): Skipping commit of aborted 
> transaction.
> [ 5111.775841] BTRFS error (device sdb5) in cleanup_transaction:1553: 
> errno=-17 Object already exists
>
>
>
> If I run balance (after unmounting and mounting the filesystem), it ends in a 
> similar way:
>
> [ 5927.338989] btrfs: relocating block group 4647284637696 flags 17
> [ 6184.333629] btrfs: found 983 extents
> [ 6269.512577] BTRFS debug (device sdb5): run_one_delayed_ref returned -17
> [ 6269.512579] [ cut here ]
> [ 6269.512636] WARNING: CPU: 7 PID: 17836 at fs/btrfs/super.c:254 
> __btrfs_abort_transaction+0x4d/0xff [btrfs]()
> [ 6269.512727] btrfs: Transaction aborted (error -17)
> [ 6269.512727] Modules linked in: ipt_MASQUERADE iptable_nat 
> nf_conntrack_ipv4 nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack ip_tables 
> x_tables cpufreq_ondemand cpufreq_conservative cpufreq_powersave 
> cpufreq_stats bridge stp llc ipv6 btrfs xor raid6_pq zlib_deflate loop pcspkr 
> button video ehci_pci ehci_hcd acpi_cpufreq i2c_i801 i2c_core lpc_ich 
> mfd_core ext4 crc16 jbd2 mbcache raid1 sg sd_mod ahci libahci libata scsi_mod 
> r8169 mii
> [ 6269.513036] CPU: 7 PID: 17836 Comm: btrfs-transacti Tainted: GW
> 3.13.0-rc4 #1
> [ 6269.513124] Hardware name: System manufacturer System Product Name/P8H77-M 
> PRO, BIOS 1101 02/04/2013
> [ 6269.513214]  0009 8807c5b07c48 8138a37d 
> 0006
> [ 6269.513304]  8807c5b07c98 8807c5b07c88 810370a9 
> 8807c5b07d80
> [ 6269.513393]  a020d524 ffef 8807ead7e800 
> 8800371eedc0
> [ 6269.513483] Call Trace:
> [ 6269.513529]  [] dump_stack+0x46/0x58
> [ 6269.513577]  [] warn_slowpath_common+0x77/0x91
> [ 6269.513627]  [] ? __btrfs_abort_transaction+0x4d/0xff 
> [btrfs]
> [ 6269.513716]  [] warn_slowpath_fmt+0x41/0x43
> [ 6269.513766]  [] __btrfs_abort_transaction+0x4d/0xff 
> [btrfs]
> [ 6269.513820]  [] btrfs_run_delayed_re

[PATCH v3] Btrfs: fix tree mod logging

2013-12-20 Thread Filipe David Borba Manana
While running the test btrfs/004 from xfstests in a loop, it failed
about 1 time out of 20 runs in my desktop. The failure happened in
the backref walking part of the test, and the test's error message was
like this:

  btrfs/004 93s ... [failed, exit status 1] - output mismatch (see 
/home/fdmanana/git/hub/xfstests_2/results//btrfs/004.out.bad)
  --- tests/btrfs/004.out   2013-11-26 18:25:29.26714 +
  +++ /home/fdmanana/git/hub/xfstests_2/results//btrfs/004.out.bad  
2013-12-10 15:25:10.327518516 +
  @@ -1,3 +1,8 @@
   QA output created by 004
   *** test backref walking
  -*** done
  +unexpected output from
  + /home/fdmanana/git/hub/btrfs-progs/btrfs inspect-internal 
logical-resolve -P 141512704 /home/fdmanana/btrfs-tests/scratch_1
  +expected inum: 405, expected address: 454656, file: 
/home/fdmanana/btrfs-tests/scratch_1/snap1/p0/d6/d3d/d156/fce, got:
  +
   ...
   (Run 'diff -u tests/btrfs/004.out 
/home/fdmanana/git/hub/xfstests_2/results//btrfs/004.out.bad' to see the entire 
diff)
  Ran: btrfs/004
  Failures: btrfs/004
  Failed 1 of 1 tests

But immediately after the test finished, the btrfs inspect-internal command
returned the expected output:

  $ btrfs inspect-internal logical-resolve -P 141512704 
/home/fdmanana/btrfs-tests/scratch_1
  inode 405 offset 454656 root 258
  inode 405 offset 454656 root 5

It turned out this was because the btrfs_search_old_slot() calls performed
during backref walking (backref.c:__resolve_indirect_ref) were not finding
anything. The reason for this turned out to be that the tree mod logging
code was not logging some node multi-step operations atomically, therefore
btrfs_search_old_slot() callers iterated often over an incomplete tree that
wasn't fully consistent with any tree state from the past. Besides missing
items, this often (but not always) resulted in -EIO errors during old slot
searches, reported in dmesg like this:

[ 4299.933936] [ cut here ]
[ 4299.933949] WARNING: CPU: 0 PID: 23190 at fs/btrfs/ctree.c:1343 
btrfs_search_old_slot+0x57b/0xab0 [btrfs]()
[ 4299.933950] Modules linked in: btrfs raid6_pq xor pci_stub vboxpci(O) 
vboxnetadp(O) vboxnetflt(O) vboxdrv(O) bnep rfcomm bluetooth parport_pc ppdev 
binfmt_misc joydev snd_hda_codec_h
[ 4299.933977] CPU: 0 PID: 23190 Comm: btrfs Tainted: GW  O 
3.12.0-fdm-btrfs-next-16+ #70
[ 4299.933978] Hardware name: To Be Filled By O.E.M. To Be Filled By O.E.M./Z77 
Pro4, BIOS P1.50 09/04/2012
[ 4299.933979]  053f 8806f3fd98f8 8176d284 
0007
[ 4299.933982]   8806f3fd9938 8104a81c 
880659c64b70
[ 4299.933984]  880659c643d0 8806599233d8 880701e2e938 
1600
[ 4299.933987] Call Trace:
[ 4299.933991]  [] dump_stack+0x55/0x76
[ 4299.933994]  [] warn_slowpath_common+0x8c/0xc0
[ 4299.933997]  [] warn_slowpath_null+0x1a/0x20
[ 4299.934003]  [] btrfs_search_old_slot+0x57b/0xab0 [btrfs]
[ 4299.934005]  [] ? _raw_read_unlock+0x2b/0x50
[ 4299.934010]  [] ? __tree_mod_log_search+0x81/0xc0 [btrfs]
[ 4299.934019]  [] __resolve_indirect_refs+0x130/0x5f0 [btrfs]
[ 4299.934027]  [] ? free_extent_buffer+0x61/0xc0 [btrfs]
[ 4299.934034]  [] find_parent_nodes+0x1fc/0xe40 [btrfs]
[ 4299.934042]  [] ? defrag_lookup_extent+0xe0/0xe0 [btrfs]
[ 4299.934048]  [] ? defrag_lookup_extent+0xe0/0xe0 [btrfs]
[ 4299.934056]  [] iterate_extent_inodes+0xe0/0x250 [btrfs]
[ 4299.934058]  [] ? _raw_spin_unlock+0x2b/0x50
[ 4299.934065]  [] iterate_inodes_from_logical+0x92/0xb0 
[btrfs]
[ 4299.934071]  [] ? defrag_lookup_extent+0xe0/0xe0 [btrfs]
[ 4299.934078]  [] btrfs_ioctl+0xf65/0x1f60 [btrfs]
[ 4299.934080]  [] ? handle_mm_fault+0x278/0xb00
[ 4299.934083]  [] ? up_read+0x23/0x40
[ 4299.934085]  [] ? __do_page_fault+0x20c/0x5a0
[ 4299.934088]  [] do_vfs_ioctl+0x96/0x570
[ 4299.934090]  [] ? error_sti+0x5/0x6
[ 4299.934093]  [] ? trace_hardirqs_off_caller+0x28/0xd0
[ 4299.934096]  [] ? retint_swapgs+0xe/0x13
[ 4299.934098]  [] SyS_ioctl+0x91/0xb0
[ 4299.934100]  [] ? trace_hardirqs_on_thunk+0x3a/0x3f
[ 4299.934102]  [] system_call_fastpath+0x16/0x1b
[ 4299.934102]  [] system_call_fastpath+0x16/0x1b
[ 4299.934104] ---[ end trace 48f0cfc902491414 ]---
[ 4299.934378] btrfs bad fsid on block 0

These tree mod log operations that must be performed atomically, 
tree_mod_log_free_eb,
tree_mod_log_eb_copy, tree_mod_log_insert_root and tree_mod_log_insert_move, 
used to
be performed atomically before the following commit:

  c8cc6341653721b54760480b0d0d9b5f09b46741
  (Btrfs: stop using GFP_ATOMIC for the tree mod log allocations)

That change removed the atomicity of such operations. This patch restores the
atomicity while still not doing the GFP_ATOMIC allocations of tree_mod_elem
structures, so it has to do the allocations using GFP_NOFS before acquiring
the mod log lock.

This issue has been experienced by several users recently, such as for example:

  http://www.spinics.net/li

Re: kernel BUG at fs/btrfs/relocation.c:1062

2013-12-20 Thread Tomasz Chmielewski
On Thu, 19 Dec 2013 22:07:37 +0900
Tomasz Chmielewski  wrote:

> If it matters, I had to hard reboot after that bug; the balance
> continued after the system booted again and I got this a while later
> (filesystem was remounted read only):

Actually, looks like the fs is quite hosed now :(

If I want to do an operation like removing a snapshot (btrfs sub
del ...), the command returns, there is IO for a few minutes, but then, the
kernel complains and fs is remounted readonly:

[ 5111.773900] BTRFS debug (device sdb5): run_one_delayed_ref returned -17
[ 5111.773902] [ cut here ]
[ 5111.773957] WARNING: CPU: 0 PID: 15042 at fs/btrfs/super.c:254 
__btrfs_abort_transaction+0x4d/0xff [btrfs]()
[ 5111.774047] btrfs: Transaction aborted (error -17)
[ 5111.774048] Modules linked in: ipt_MASQUERADE iptable_nat nf_conntrack_ipv4 
nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack ip_tables x_tables 
cpufreq_ondemand cpufreq_conservative cpufreq_powersave cpufreq_stats bridge 
stp llc ipv6 btrfs xor raid6_pq zlib_deflate loop pcspkr button video ehci_pci 
ehci_hcd acpi_cpufreq i2c_i801 i2c_core lpc_ich mfd_core ext4 crc16 jbd2 
mbcache raid1 sg sd_mod ahci libahci libata scsi_mod r8169 mii
[ 5111.774355] CPU: 0 PID: 15042 Comm: btrfs-transacti Tainted: GW
3.13.0-rc4 #1
[ 5111.774443] Hardware name: System manufacturer System Product Name/P8H77-M 
PRO, BIOS 1101 02/04/2013
[ 5111.774533]  0009 8800374ddc48 8138a37d 
0006
[ 5111.774622]  8800374ddc98 8800374ddc88 810370a9 
8800374ddd80
[ 5111.774711]  a020d524 ffef 8807ead7d800 
8807ff0cc8c0
[ 5111.774800] Call Trace:
[ 5111.774846]  [] dump_stack+0x46/0x58
[ 5111.774894]  [] warn_slowpath_common+0x77/0x91
[ 5111.774944]  [] ? __btrfs_abort_transaction+0x4d/0xff 
[btrfs]
[ 5111.775032]  [] warn_slowpath_fmt+0x41/0x43
[ 5111.775081]  [] __btrfs_abort_transaction+0x4d/0xff [btrfs]
[ 5111.775135]  [] btrfs_run_delayed_refs+0x253/0x46f [btrfs]
[ 5111.775189]  [] btrfs_commit_transaction+0x36d/0x7df 
[btrfs]
[ 5111.775281]  [] transaction_kthread+0xef/0x1c2 [btrfs]
[ 5111.775333]  [] ? open_ctree+0x1ac7/0x1ac7 [btrfs]
[ 5111.775382]  [] kthread+0xcd/0xd5
[ 5111.775428]  [] ? kthread_freezable_should_stop+0x43/0x43
[ 5111.775477]  [] ret_from_fork+0x7c/0xb0
[ 5111.775524]  [] ? kthread_freezable_should_stop+0x43/0x43
[ 5111.775572] ---[ end trace b552aca9a0cff3cb ]---
[ 5111.775618] BTRFS error (device sdb5) in btrfs_run_delayed_refs:2730: 
errno=-17 Object already exists
[ 5111.775707] BTRFS info (device sdb5): forced readonly
[ 5111.775754] BTRFS warning (device sdb5): Skipping commit of aborted 
transaction.
[ 5111.775841] BTRFS error (device sdb5) in cleanup_transaction:1553: errno=-17 
Object already exists



If I run balance (after unmounting and mounting the filesystem), it ends in a 
similar way:

[ 5927.338989] btrfs: relocating block group 4647284637696 flags 17
[ 6184.333629] btrfs: found 983 extents
[ 6269.512577] BTRFS debug (device sdb5): run_one_delayed_ref returned -17
[ 6269.512579] [ cut here ]
[ 6269.512636] WARNING: CPU: 7 PID: 17836 at fs/btrfs/super.c:254 
__btrfs_abort_transaction+0x4d/0xff [btrfs]()
[ 6269.512727] btrfs: Transaction aborted (error -17)
[ 6269.512727] Modules linked in: ipt_MASQUERADE iptable_nat nf_conntrack_ipv4 
nf_defrag_ipv4 nf_nat_ipv4 nf_nat nf_conntrack ip_tables x_tables 
cpufreq_ondemand cpufreq_conservative cpufreq_powersave cpufreq_stats bridge 
stp llc ipv6 btrfs xor raid6_pq zlib_deflate loop pcspkr button video ehci_pci 
ehci_hcd acpi_cpufreq i2c_i801 i2c_core lpc_ich mfd_core ext4 crc16 jbd2 
mbcache raid1 sg sd_mod ahci libahci libata scsi_mod r8169 mii
[ 6269.513036] CPU: 7 PID: 17836 Comm: btrfs-transacti Tainted: GW
3.13.0-rc4 #1
[ 6269.513124] Hardware name: System manufacturer System Product Name/P8H77-M 
PRO, BIOS 1101 02/04/2013
[ 6269.513214]  0009 8807c5b07c48 8138a37d 
0006
[ 6269.513304]  8807c5b07c98 8807c5b07c88 810370a9 
8807c5b07d80
[ 6269.513393]  a020d524 ffef 8807ead7e800 
8800371eedc0
[ 6269.513483] Call Trace:
[ 6269.513529]  [] dump_stack+0x46/0x58
[ 6269.513577]  [] warn_slowpath_common+0x77/0x91
[ 6269.513627]  [] ? __btrfs_abort_transaction+0x4d/0xff 
[btrfs]
[ 6269.513716]  [] warn_slowpath_fmt+0x41/0x43
[ 6269.513766]  [] __btrfs_abort_transaction+0x4d/0xff [btrfs]
[ 6269.513820]  [] btrfs_run_delayed_refs+0x253/0x46f [btrfs]
[ 6269.513874]  [] btrfs_commit_transaction+0x70/0x7df [btrfs]
[ 6269.513927]  [] transaction_kthread+0xef/0x1c2 [btrfs]
[ 6269.513980]  [] ? open_ctree+0x1ac7/0x1ac7 [btrfs]
[ 6269.514029]  [] kthread+0xcd/0xd5
[ 6269.514076]  [] ? kthread_freezable_should_stop+0x43/0x43
[ 6269.514125]  [] ret_from_fork+0x7c/0xb0
[ 6269.514172]  [] ? kthread_freezable_should_stop+0x43/0x43
[ 6269.514220] ---[ end trace b552aca9a0cff3cc ]---
[ 6269.514266] 

Re: [PATCH v5] Btrfs: convert printk to btrfs_ and fix BTRFS prefix

2013-12-20 Thread Josef Bacik

Still failing to build

fs/btrfs/tests/extent-io-tests.c: In function ‘process_page_range’:
fs/btrfs/tests/extent-io-tests.c:59:4: error: implicit declaration of 
function ‘btrfs_err’ [-Werror=implicit-function-declaration]

btrfs_err(BTRFS_I(inode)->root->fs_info,
^
fs/btrfs/tests/extent-io-tests.c:59:4: error: implicit declaration of 
function ‘BTRFS_I’ [-Werror=implicit-function-declaration]
fs/btrfs/tests/extent-io-tests.c:59:28: error: invalid type argument of 
‘->’ (have ‘int’)

btrfs_err(BTRFS_I(inode)->root->fs_info,
^
Make sure you have the sanity tests config option enabled so you can 
make sure everything is getting built. Thanks,


Josef
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 01/21] reiserfs: prefix ACL symbols with reiserfs_

2013-12-20 Thread Christoph Hellwig
Signed-off-by: Christoph Hellwig 
Reviewed-by: Jan Kara 
---
 fs/reiserfs/xattr_acl.c |   20 ++--
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/fs/reiserfs/xattr_acl.c b/fs/reiserfs/xattr_acl.c
index 06c04f7..6f721ea 100644
--- a/fs/reiserfs/xattr_acl.c
+++ b/fs/reiserfs/xattr_acl.c
@@ -16,7 +16,7 @@ static int reiserfs_set_acl(struct 
reiserfs_transaction_handle *th,
struct posix_acl *acl);
 
 static int
-posix_acl_set(struct dentry *dentry, const char *name, const void *value,
+reiserfs_posix_acl_set(struct dentry *dentry, const char *name, const void 
*value,
size_t size, int flags, int type)
 {
struct inode *inode = dentry->d_inode;
@@ -65,7 +65,7 @@ posix_acl_set(struct dentry *dentry, const char *name, const 
void *value,
 }
 
 static int
-posix_acl_get(struct dentry *dentry, const char *name, void *buffer,
+reiserfs_posix_acl_get(struct dentry *dentry, const char *name, void *buffer,
size_t size, int type)
 {
struct posix_acl *acl;
@@ -88,7 +88,7 @@ posix_acl_get(struct dentry *dentry, const char *name, void 
*buffer,
 /*
  * Convert from filesystem to in-memory representation.
  */
-static struct posix_acl *posix_acl_from_disk(const void *value, size_t size)
+static struct posix_acl *reiserfs_posix_acl_from_disk(const void *value, 
size_t size)
 {
const char *end = (char *)value + size;
int n, count;
@@ -158,7 +158,7 @@ static struct posix_acl *posix_acl_from_disk(const void 
*value, size_t size)
 /*
  * Convert from in-memory to filesystem representation.
  */
-static void *posix_acl_to_disk(const struct posix_acl *acl, size_t * size)
+static void *reiserfs_posix_acl_to_disk(const struct posix_acl *acl, size_t * 
size)
 {
reiserfs_acl_header *ext_acl;
char *e;
@@ -257,7 +257,7 @@ struct posix_acl *reiserfs_get_acl(struct inode *inode, int 
type)
} else if (retval < 0) {
acl = ERR_PTR(retval);
} else {
-   acl = posix_acl_from_disk(value, retval);
+   acl = reiserfs_posix_acl_from_disk(value, retval);
}
if (!IS_ERR(acl))
set_cached_acl(inode, type, acl);
@@ -307,7 +307,7 @@ reiserfs_set_acl(struct reiserfs_transaction_handle *th, 
struct inode *inode,
}
 
if (acl) {
-   value = posix_acl_to_disk(acl, &size);
+   value = reiserfs_posix_acl_to_disk(acl, &size);
if (IS_ERR(value))
return (int)PTR_ERR(value);
}
@@ -499,8 +499,8 @@ static size_t posix_acl_access_list(struct dentry *dentry, 
char *list,
 const struct xattr_handler reiserfs_posix_acl_access_handler = {
.prefix = POSIX_ACL_XATTR_ACCESS,
.flags = ACL_TYPE_ACCESS,
-   .get = posix_acl_get,
-   .set = posix_acl_set,
+   .get = reiserfs_posix_acl_get,
+   .set = reiserfs_posix_acl_set,
.list = posix_acl_access_list,
 };
 
@@ -519,7 +519,7 @@ static size_t posix_acl_default_list(struct dentry *dentry, 
char *list,
 const struct xattr_handler reiserfs_posix_acl_default_handler = {
.prefix = POSIX_ACL_XATTR_DEFAULT,
.flags = ACL_TYPE_DEFAULT,
-   .get = posix_acl_get,
-   .set = posix_acl_set,
+   .get = reiserfs_posix_acl_get,
+   .set = reiserfs_posix_acl_set,
.list = posix_acl_default_list,
 };
-- 
1.7.10.4


--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 05/21] fs: add generic xattr_acl handlers

2013-12-20 Thread Christoph Hellwig
With the ->set_acl inode operation we can implement the Posix ACL
xattr handlers in generic code instead of duplicating them all
over the tree.

Signed-off-by: Christoph Hellwig 
Reviewed-by: Jan Kara 
---
 fs/posix_acl.c  |  102 +++
 include/linux/posix_acl_xattr.h |3 ++
 2 files changed, 105 insertions(+)

diff --git a/fs/posix_acl.c b/fs/posix_acl.c
index e329c21..3c0f659 100644
--- a/fs/posix_acl.c
+++ b/fs/posix_acl.c
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -610,3 +611,104 @@ posix_acl_to_xattr(struct user_namespace *user_ns, const 
struct posix_acl *acl,
return real_size;
 }
 EXPORT_SYMBOL (posix_acl_to_xattr);
+
+static int
+posix_acl_xattr_get(struct dentry *dentry, const char *name,
+   void *value, size_t size, int type)
+{
+   struct posix_acl *acl;
+   int error;
+
+   if (!IS_POSIXACL(dentry->d_inode))
+   return -EOPNOTSUPP;
+   if (S_ISLNK(dentry->d_inode->i_mode))
+   return -EOPNOTSUPP;
+
+   acl = get_acl(dentry->d_inode, type);
+   if (IS_ERR(acl))
+   return PTR_ERR(acl);
+   if (acl == NULL)
+   return -ENODATA;
+
+   error = posix_acl_to_xattr(&init_user_ns, acl, value, size);
+   posix_acl_release(acl);
+
+   return error;
+}
+
+static int
+posix_acl_xattr_set(struct dentry *dentry, const char *name,
+   const void *value, size_t size, int flags, int type)
+{
+   struct inode *inode = dentry->d_inode;
+   struct posix_acl *acl = NULL;
+   int ret;
+
+   if (!IS_POSIXACL(inode))
+   return -EOPNOTSUPP;
+   if (!inode->i_op->set_acl)
+   return -EOPNOTSUPP;
+
+   if (type == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode))
+   return value ? -EACCES : 0;
+   if (!inode_owner_or_capable(inode))
+   return -EPERM;
+
+   if (value) {
+   acl = posix_acl_from_xattr(&init_user_ns, value, size);
+   if (IS_ERR(acl))
+   return PTR_ERR(acl);
+
+   if (acl) {
+   ret = posix_acl_valid(acl);
+   if (ret)
+   goto out;
+   }
+   }
+
+   ret = inode->i_op->set_acl(inode, acl, type);
+out:
+   posix_acl_release(acl);
+   return ret;
+}
+
+static size_t
+posix_acl_xattr_list(struct dentry *dentry, char *list, size_t list_size,
+   const char *name, size_t name_len, int type)
+{
+   const char *xname;
+   size_t size;
+
+   if (!IS_POSIXACL(dentry->d_inode))
+   return -EOPNOTSUPP;
+   if (S_ISLNK(dentry->d_inode->i_mode))
+   return -EOPNOTSUPP;
+
+   if (type == ACL_TYPE_ACCESS)
+   xname = POSIX_ACL_XATTR_ACCESS;
+   else
+   xname = POSIX_ACL_XATTR_DEFAULT;
+
+   size = strlen(xname) + 1;
+   if (list && size <= list_size)
+   memcpy(list, xname, size);
+   return size;
+}
+
+const struct xattr_handler posix_acl_access_xattr_handler = {
+   .prefix = POSIX_ACL_XATTR_ACCESS,
+   .flags = ACL_TYPE_ACCESS,
+   .list = posix_acl_xattr_list,
+   .get = posix_acl_xattr_get,
+   .set = posix_acl_xattr_set,
+};
+EXPORT_SYMBOL_GPL(posix_acl_access_xattr_handler);
+
+const struct xattr_handler posix_acl_default_xattr_handler = {
+   .prefix = POSIX_ACL_XATTR_DEFAULT,
+   .flags = ACL_TYPE_DEFAULT,
+   .list = posix_acl_xattr_list,
+   .get = posix_acl_xattr_get,
+   .set = posix_acl_xattr_set,
+};
+EXPORT_SYMBOL_GPL(posix_acl_default_xattr_handler);
diff --git a/include/linux/posix_acl_xattr.h b/include/linux/posix_acl_xattr.h
index ad93ad0..6f14ee2 100644
--- a/include/linux/posix_acl_xattr.h
+++ b/include/linux/posix_acl_xattr.h
@@ -69,4 +69,7 @@ struct posix_acl *posix_acl_from_xattr(struct user_namespace 
*user_ns,
 int posix_acl_to_xattr(struct user_namespace *user_ns,
   const struct posix_acl *acl, void *buffer, size_t size);
 
+extern const struct xattr_handler posix_acl_access_xattr_handler;
+extern const struct xattr_handler posix_acl_default_xattr_handler;
+
 #endif /* _POSIX_ACL_XATTR_H */
-- 
1.7.10.4


--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 06/21] fs: make posix_acl_chmod more useful

2013-12-20 Thread Christoph Hellwig
Rename the current posix_acl_chmod to __posix_acl_chmod and add
a fully featured ACL chmod helper that uses the ->set_acl inode
operation.

Signed-off-by: Christoph Hellwig 
Reviewed-by: Jan Kara 
---
 fs/9p/acl.c   |2 +-
 fs/btrfs/acl.c|2 +-
 fs/ext2/acl.c |2 +-
 fs/ext3/acl.c |2 +-
 fs/ext4/acl.c |2 +-
 fs/f2fs/acl.c |2 +-
 fs/generic_acl.c  |2 +-
 fs/gfs2/acl.c |2 +-
 fs/hfsplus/posix_acl.c|2 +-
 fs/jffs2/acl.c|2 +-
 fs/jfs/acl.c  |2 +-
 fs/ocfs2/acl.c|2 +-
 fs/posix_acl.c|   30 +++---
 fs/reiserfs/xattr_acl.c   |2 +-
 fs/xfs/xfs_acl.c  |2 +-
 include/linux/posix_acl.h |   17 +
 16 files changed, 54 insertions(+), 21 deletions(-)

diff --git a/fs/9p/acl.c b/fs/9p/acl.c
index 7af425f..f5ce5c5 100644
--- a/fs/9p/acl.c
+++ b/fs/9p/acl.c
@@ -156,7 +156,7 @@ int v9fs_acl_chmod(struct inode *inode, struct p9_fid *fid)
return -EOPNOTSUPP;
acl = v9fs_get_cached_acl(inode, ACL_TYPE_ACCESS);
if (acl) {
-   retval = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
+   retval = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
if (retval)
return retval;
set_cached_acl(inode, ACL_TYPE_ACCESS, acl);
diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c
index 0890c83..1af04ff 100644
--- a/fs/btrfs/acl.c
+++ b/fs/btrfs/acl.c
@@ -256,7 +256,7 @@ int btrfs_acl_chmod(struct inode *inode)
if (IS_ERR_OR_NULL(acl))
return PTR_ERR(acl);
 
-   ret = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
+   ret = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
if (ret)
return ret;
ret = btrfs_set_acl(NULL, inode, acl, ACL_TYPE_ACCESS);
diff --git a/fs/ext2/acl.c b/fs/ext2/acl.c
index 110b6b3..7006ced 100644
--- a/fs/ext2/acl.c
+++ b/fs/ext2/acl.c
@@ -308,7 +308,7 @@ ext2_acl_chmod(struct inode *inode)
acl = ext2_get_acl(inode, ACL_TYPE_ACCESS);
if (IS_ERR(acl) || !acl)
return PTR_ERR(acl);
-   error = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
+   error = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
if (error)
return error;
error = ext2_set_acl(inode, ACL_TYPE_ACCESS, acl);
diff --git a/fs/ext3/acl.c b/fs/ext3/acl.c
index dbb5ad5..6691a6c 100644
--- a/fs/ext3/acl.c
+++ b/fs/ext3/acl.c
@@ -314,7 +314,7 @@ ext3_acl_chmod(struct inode *inode)
acl = ext3_get_acl(inode, ACL_TYPE_ACCESS);
if (IS_ERR(acl) || !acl)
return PTR_ERR(acl);
-   error = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
+   error = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
if (error)
return error;
 retry:
diff --git a/fs/ext4/acl.c b/fs/ext4/acl.c
index 39a54a0..2eebe02 100644
--- a/fs/ext4/acl.c
+++ b/fs/ext4/acl.c
@@ -320,7 +320,7 @@ ext4_acl_chmod(struct inode *inode)
acl = ext4_get_acl(inode, ACL_TYPE_ACCESS);
if (IS_ERR(acl) || !acl)
return PTR_ERR(acl);
-   error = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
+   error = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
if (error)
return error;
 retry:
diff --git a/fs/f2fs/acl.c b/fs/f2fs/acl.c
index d0fc287..14c4df0 100644
--- a/fs/f2fs/acl.c
+++ b/fs/f2fs/acl.c
@@ -311,7 +311,7 @@ int f2fs_acl_chmod(struct inode *inode)
if (IS_ERR(acl) || !acl)
return PTR_ERR(acl);
 
-   error = posix_acl_chmod(&acl, GFP_KERNEL, mode);
+   error = __posix_acl_chmod(&acl, GFP_KERNEL, mode);
if (error)
return error;
 
diff --git a/fs/generic_acl.c b/fs/generic_acl.c
index b3f3676..46a5076 100644
--- a/fs/generic_acl.c
+++ b/fs/generic_acl.c
@@ -158,7 +158,7 @@ generic_acl_chmod(struct inode *inode)
return -EOPNOTSUPP;
acl = get_cached_acl(inode, ACL_TYPE_ACCESS);
if (acl) {
-   error = posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
+   error = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
if (error)
return error;
set_cached_acl(inode, ACL_TYPE_ACCESS, acl);
diff --git a/fs/gfs2/acl.c b/fs/gfs2/acl.c
index f69ac0a..3e200c7 100644
--- a/fs/gfs2/acl.c
+++ b/fs/gfs2/acl.c
@@ -162,7 +162,7 @@ int gfs2_acl_chmod(struct gfs2_inode *ip, struct iattr 
*attr)
if (!acl)
return gfs2_setattr_simple(inode, attr);
 
-   error = posix_acl_chmod(&acl, GFP_NOFS, attr->ia_mode);
+   error = __posix_acl_chmod(&acl, GFP_NOFS, attr->ia_mode);
if (error)
return error;
 
diff --git a/fs/hfsplus/posix_acl.c b/fs/hfsplus/posix_acl.c
index b609cc1..cab5fd6 100644
--- a/fs/hfsplus/p

[PATCH 04/21] fs: add a set_acl inode operation

2013-12-20 Thread Christoph Hellwig
This will allow moving all the Posix ACL handling into the VFS and clean
up tons of cruft in the filesystems.

Signed-off-by: Christoph Hellwig 
Reviewed-by: Jan Kara 
---
 include/linux/fs.h |1 +
 1 file changed, 1 insertion(+)

diff --git a/include/linux/fs.h b/include/linux/fs.h
index 121f11f..09f553c 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1580,6 +1580,7 @@ struct inode_operations {
   struct file *, unsigned open_flag,
   umode_t create_mode, int *opened);
int (*tmpfile) (struct inode *, struct dentry *, umode_t);
+   int (*set_acl)(struct inode *, struct posix_acl *, int);
 } cacheline_aligned;
 
 ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,
-- 
1.7.10.4


--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v4 00/18] Replace btrfs_workers with kernel workqueue based btrfs_workqueue

2013-12-20 Thread Josef Bacik


On 12/19/2013 07:08 PM, Qu Wenruo wrote:

I'm sorry but I failed to reproduce the problem.
Btrfs/012 in xfstests has been run for serveral hours but nothing 
happened.


Would you please give me some more details about the environment or 
the panic backtrace?




Ok so it wasn't that test, it was just ./check -g auto.  It would 
sometimes die at btrfs/012, other times it would make it as far as 
generic/083 before it keeled over.  I bisected it down to


btrfs: Replace fs_info->workers with btrfs_workqueue

which of course is just the first patch that you start using the new 
code which isn't helpful.  My dmesg from one of my runs is here


http://ur1.ca/g867b

All of the initial panics looked exactly the same.  I'm just going to 
kick the series out for now while you track down the problem. Thanks,


Josef
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 00/21] Consolidate Posix ACL implementation V3

2013-12-20 Thread Christoph Hellwig
This series consolidates the various cut'n'pasted Posix ACL implementations
into a single common one based on the ->get_acl method Linus added a while
ago and a new ->set_acl counterpart.

This remove ~1800 lines of code and provides a single place to implement
various nasty little gems of the semantics.

Unfortunately the 9p code is still left out - it implements the ACLs
in two very weird ways, one using the common code but on the client only,
and one pasing things straight through to the server.  We could easily
convert it to the new code on the write side if ->set_acl took a dentry,
but there's no cance to do that on the ->get_acl side.  Ideas how to
handle it welcome.

After that we'd be ready to never go into the fs for the ACL attributes
and branch straight to the ACL code below the syscall, repairing the
old API braindamage of overloading ACLs onto the xattrs.


Changes from V2:
 - remove redundant S_ISLNK checks
 - fix the get_acl return value
 - remove spurious symlink get_acl instance in gfs2
 - fix default ACL inheritance on NFS
 - use get_acl and set_acl from the NFS server
 - remove some incorrectly copy&pasted code in hfsplus

Changes from V1:
 - check for symlinks in the ACL code and remove checks in the lower
   level functions.
 - remove get_acl instances for symlinks in a few filesystems
 - pass a umode_t mode argument to posix_acl_chmod to accomodate f2fs
 - various cosemtic bits from the reviews.

Note that I still haven't heard from ocfs2 folks, so the patch is left
unchanged.

--
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
___
Jfs-discussion mailing list
jfs-discuss...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jfs-discussion
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 07/21] fs: make posix_acl_create more useful

2013-12-20 Thread Christoph Hellwig
Rename the current posix_acl_created to __posix_acl_create and add
a fully featured helper to set up the ACLs on file creation that
uses get_acl().

Signed-off-by: Christoph Hellwig 
Reviewed-by: Jan Kara 
---
 fs/9p/acl.c   |2 +-
 fs/btrfs/acl.c|2 +-
 fs/ext2/acl.c |2 +-
 fs/ext3/acl.c |2 +-
 fs/ext4/acl.c |2 +-
 fs/f2fs/acl.c |2 +-
 fs/generic_acl.c  |2 +-
 fs/gfs2/acl.c |2 +-
 fs/hfsplus/posix_acl.c|2 +-
 fs/jffs2/acl.c|2 +-
 fs/jfs/acl.c  |2 +-
 fs/nfs/nfs3acl.c  |2 +-
 fs/ocfs2/acl.c|2 +-
 fs/posix_acl.c|   57 +
 fs/reiserfs/xattr_acl.c   |2 +-
 fs/xfs/xfs_acl.c  |4 ++--
 include/linux/posix_acl.h |8 ---
 17 files changed, 74 insertions(+), 23 deletions(-)

diff --git a/fs/9p/acl.c b/fs/9p/acl.c
index f5ce5c5..8482f2d 100644
--- a/fs/9p/acl.c
+++ b/fs/9p/acl.c
@@ -200,7 +200,7 @@ int v9fs_acl_mode(struct inode *dir, umode_t *modep,
if (acl) {
if (S_ISDIR(mode))
*dpacl = posix_acl_dup(acl);
-   retval = posix_acl_create(&acl, GFP_NOFS, &mode);
+   retval = __posix_acl_create(&acl, GFP_NOFS, &mode);
if (retval < 0)
return retval;
if (retval > 0)
diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c
index 1af04ff..b56519d 100644
--- a/fs/btrfs/acl.c
+++ b/fs/btrfs/acl.c
@@ -222,7 +222,7 @@ int btrfs_init_acl(struct btrfs_trans_handle *trans,
if (ret)
goto failed;
}
-   ret = posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
+   ret = __posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
if (ret < 0)
return ret;
 
diff --git a/fs/ext2/acl.c b/fs/ext2/acl.c
index 7006ced..6e842a7 100644
--- a/fs/ext2/acl.c
+++ b/fs/ext2/acl.c
@@ -268,7 +268,7 @@ ext2_init_acl(struct inode *inode, struct inode *dir)
if (error)
goto cleanup;
}
-   error = posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
+   error = __posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
if (error < 0)
return error;
if (error > 0) {
diff --git a/fs/ext3/acl.c b/fs/ext3/acl.c
index 6691a6c..4f3d8fa 100644
--- a/fs/ext3/acl.c
+++ b/fs/ext3/acl.c
@@ -271,7 +271,7 @@ ext3_init_acl(handle_t *handle, struct inode *inode, struct 
inode *dir)
if (error)
goto cleanup;
}
-   error = posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
+   error = __posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
if (error < 0)
return error;
 
diff --git a/fs/ext4/acl.c b/fs/ext4/acl.c
index 2eebe02..f827f3b 100644
--- a/fs/ext4/acl.c
+++ b/fs/ext4/acl.c
@@ -276,7 +276,7 @@ ext4_init_acl(handle_t *handle, struct inode *inode, struct 
inode *dir)
if (error)
goto cleanup;
}
-   error = posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
+   error = __posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
if (error < 0)
return error;
 
diff --git a/fs/f2fs/acl.c b/fs/f2fs/acl.c
index 14c4df0..45e8430 100644
--- a/fs/f2fs/acl.c
+++ b/fs/f2fs/acl.c
@@ -285,7 +285,7 @@ int f2fs_init_acl(struct inode *inode, struct inode *dir, 
struct page *ipage)
if (error)
goto cleanup;
}
-   error = posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
+   error = __posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
if (error < 0)
return error;
if (error > 0)
diff --git a/fs/generic_acl.c b/fs/generic_acl.c
index 46a5076..4357f39 100644
--- a/fs/generic_acl.c
+++ b/fs/generic_acl.c
@@ -128,7 +128,7 @@ generic_acl_init(struct inode *inode, struct inode *dir)
if (acl) {
if (S_ISDIR(inode->i_mode))
set_cached_acl(inode, ACL_TYPE_DEFAULT, acl);
-   error = posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
+   error = __posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
if (error < 0)
return error;
if (error > 0)
diff --git a/fs/gfs2/acl.c b/fs/gfs2/acl.c
index 3e200c7..e82e4ac 100644
--- a/fs/gfs2/acl.c
+++ b/fs/gfs2/acl.c
@@ -131,7 +131,7 @@ int gfs2_acl_create(struct gfs2_inode *dip, struct inode 
*inode)
goto out;
}
 
-   error = posix_acl_create(&acl, GFP_NOFS, &mode);
+   error = __posix_acl_create(&acl, GFP_NOFS

[PATCH 08/21] btrfs: use generic posix ACL infrastructure

2013-12-20 Thread Christoph Hellwig
Also don't bother to set up a .get_acl method for symlinks as we do not
support access control (ACLs or even mode bits) for symlinks in Linux.

Signed-off-by: Christoph Hellwig 
---
 fs/btrfs/acl.c   |  142 +++---
 fs/btrfs/ctree.h |7 +--
 fs/btrfs/inode.c |7 ++-
 fs/btrfs/xattr.c |5 +-
 fs/btrfs/xattr.h |2 -
 5 files changed, 28 insertions(+), 135 deletions(-)

diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c
index b56519d..ff9b399 100644
--- a/fs/btrfs/acl.c
+++ b/fs/btrfs/acl.c
@@ -35,13 +35,6 @@ struct posix_acl *btrfs_get_acl(struct inode *inode, int 
type)
char *value = NULL;
struct posix_acl *acl;
 
-   if (!IS_POSIXACL(inode))
-   return NULL;
-
-   acl = get_cached_acl(inode, type);
-   if (acl != ACL_NOT_CACHED)
-   return acl;
-
switch (type) {
case ACL_TYPE_ACCESS:
name = POSIX_ACL_XATTR_ACCESS;
@@ -76,31 +69,10 @@ struct posix_acl *btrfs_get_acl(struct inode *inode, int 
type)
return acl;
 }
 
-static int btrfs_xattr_acl_get(struct dentry *dentry, const char *name,
-   void *value, size_t size, int type)
-{
-   struct posix_acl *acl;
-   int ret = 0;
-
-   if (!IS_POSIXACL(dentry->d_inode))
-   return -EOPNOTSUPP;
-
-   acl = btrfs_get_acl(dentry->d_inode, type);
-
-   if (IS_ERR(acl))
-   return PTR_ERR(acl);
-   if (acl == NULL)
-   return -ENODATA;
-   ret = posix_acl_to_xattr(&init_user_ns, acl, value, size);
-   posix_acl_release(acl);
-
-   return ret;
-}
-
 /*
  * Needs to be called with fs_mutex held
  */
-static int btrfs_set_acl(struct btrfs_trans_handle *trans,
+static int __btrfs_set_acl(struct btrfs_trans_handle *trans,
 struct inode *inode, struct posix_acl *acl, int type)
 {
int ret, size = 0;
@@ -158,35 +130,9 @@ out:
return ret;
 }
 
-static int btrfs_xattr_acl_set(struct dentry *dentry, const char *name,
-   const void *value, size_t size, int flags, int type)
+int btrfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
 {
-   int ret;
-   struct posix_acl *acl = NULL;
-
-   if (!inode_owner_or_capable(dentry->d_inode))
-   return -EPERM;
-
-   if (!IS_POSIXACL(dentry->d_inode))
-   return -EOPNOTSUPP;
-
-   if (value) {
-   acl = posix_acl_from_xattr(&init_user_ns, value, size);
-   if (IS_ERR(acl))
-   return PTR_ERR(acl);
-
-   if (acl) {
-   ret = posix_acl_valid(acl);
-   if (ret)
-   goto out;
-   }
-   }
-
-   ret = btrfs_set_acl(NULL, dentry->d_inode, acl, type);
-out:
-   posix_acl_release(acl);
-
-   return ret;
+   return __btrfs_set_acl(NULL, inode, acl, type);
 }
 
 /*
@@ -197,83 +143,31 @@ out:
 int btrfs_init_acl(struct btrfs_trans_handle *trans,
   struct inode *inode, struct inode *dir)
 {
-   struct posix_acl *acl = NULL;
+   struct posix_acl *default_acl, *acl;
int ret = 0;
 
/* this happens with subvols */
if (!dir)
return 0;
 
-   if (!S_ISLNK(inode->i_mode)) {
-   if (IS_POSIXACL(dir)) {
-   acl = btrfs_get_acl(dir, ACL_TYPE_DEFAULT);
-   if (IS_ERR(acl))
-   return PTR_ERR(acl);
-   }
+   ret = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
+   if (ret)
+   return ret;
 
-   if (!acl)
-   inode->i_mode &= ~current_umask();
+   if (default_acl) {
+   ret = __btrfs_set_acl(trans, inode, default_acl,
+ ACL_TYPE_DEFAULT);
+   posix_acl_release(default_acl);
}
 
-   if (IS_POSIXACL(dir) && acl) {
-   if (S_ISDIR(inode->i_mode)) {
-   ret = btrfs_set_acl(trans, inode, acl,
-   ACL_TYPE_DEFAULT);
-   if (ret)
-   goto failed;
-   }
-   ret = __posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
-   if (ret < 0)
-   return ret;
-
-   if (ret > 0) {
-   /* we need an acl */
-   ret = btrfs_set_acl(trans, inode, acl, ACL_TYPE_ACCESS);
-   } else if (ret < 0) {
-   cache_no_acl(inode);
-   }
-   } else {
-   cache_no_acl(inode);
+   if (acl) {
+   if (!ret)
+   ret = __btrfs_set_acl(trans, inode, acl,
+ ACL_TYPE_ACCESS);
+   posix_acl_release(acl);
}
-failed:
-   posix_acl_release(acl);
-
-   

[PATCH 02/21] fs: merge xattr_acl.c into posix_acl.c

2013-12-20 Thread Christoph Hellwig
Signed-off-by: Christoph Hellwig 
---
 fs/Makefile|2 +-
 fs/posix_acl.c |  180 +---
 fs/xattr_acl.c |  180 
 3 files changed, 174 insertions(+), 188 deletions(-)
 delete mode 100644 fs/xattr_acl.c

diff --git a/fs/Makefile b/fs/Makefile
index 4fe6df3..f2c1843 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -42,7 +42,7 @@ obj-$(CONFIG_BINFMT_SOM)  += binfmt_som.o
 obj-$(CONFIG_BINFMT_FLAT)  += binfmt_flat.o
 
 obj-$(CONFIG_FS_MBCACHE)   += mbcache.o
-obj-$(CONFIG_FS_POSIX_ACL) += posix_acl.o xattr_acl.o
+obj-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
 obj-$(CONFIG_NFS_COMMON)   += nfs_common/
 obj-$(CONFIG_GENERIC_ACL)  += generic_acl.o
 obj-$(CONFIG_COREDUMP) += coredump.o
diff --git a/fs/posix_acl.c b/fs/posix_acl.c
index 8bd2135..359d70b 100644
--- a/fs/posix_acl.c
+++ b/fs/posix_acl.c
@@ -1,10 +1,8 @@
 /*
- * linux/fs/posix_acl.c
+ * Copyright (C) 2002,2003 by Andreas Gruenbacher 
  *
- *  Copyright (C) 2002 by Andreas Gruenbacher 
- *
- *  Fixes from William Schumacher incorporated on 15 March 2001.
- * (Reported by Charles Bertsch, ).
+ * Fixes from William Schumacher incorporated on 15 March 2001.
+ *(Reported by Charles Bertsch, ).
  */
 
 /*
@@ -18,9 +16,9 @@
 #include 
 #include 
 #include 
+#include 
 #include 
-
-#include 
+#include 
 
 EXPORT_SYMBOL(posix_acl_init);
 EXPORT_SYMBOL(posix_acl_alloc);
@@ -418,3 +416,171 @@ posix_acl_chmod(struct posix_acl **acl, gfp_t gfp, 
umode_t mode)
return err;
 }
 EXPORT_SYMBOL(posix_acl_chmod);
+
+/*
+ * Fix up the uids and gids in posix acl extended attributes in place.
+ */
+static void posix_acl_fix_xattr_userns(
+   struct user_namespace *to, struct user_namespace *from,
+   void *value, size_t size)
+{
+   posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
+   posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), 
*end;
+   int count;
+   kuid_t uid;
+   kgid_t gid;
+
+   if (!value)
+   return;
+   if (size < sizeof(posix_acl_xattr_header))
+   return;
+   if (header->a_version != cpu_to_le32(POSIX_ACL_XATTR_VERSION))
+   return;
+
+   count = posix_acl_xattr_count(size);
+   if (count < 0)
+   return;
+   if (count == 0)
+   return;
+
+   for (end = entry + count; entry != end; entry++) {
+   switch(le16_to_cpu(entry->e_tag)) {
+   case ACL_USER:
+   uid = make_kuid(from, le32_to_cpu(entry->e_id));
+   entry->e_id = cpu_to_le32(from_kuid(to, uid));
+   break;
+   case ACL_GROUP:
+   gid = make_kgid(from, le32_to_cpu(entry->e_id));
+   entry->e_id = cpu_to_le32(from_kgid(to, gid));
+   break;
+   default:
+   break;
+   }
+   }
+}
+
+void posix_acl_fix_xattr_from_user(void *value, size_t size)
+{
+   struct user_namespace *user_ns = current_user_ns();
+   if (user_ns == &init_user_ns)
+   return;
+   posix_acl_fix_xattr_userns(&init_user_ns, user_ns, value, size);
+}
+
+void posix_acl_fix_xattr_to_user(void *value, size_t size)
+{
+   struct user_namespace *user_ns = current_user_ns();
+   if (user_ns == &init_user_ns)
+   return;
+   posix_acl_fix_xattr_userns(user_ns, &init_user_ns, value, size);
+}
+
+/*
+ * Convert from extended attribute to in-memory representation.
+ */
+struct posix_acl *
+posix_acl_from_xattr(struct user_namespace *user_ns,
+const void *value, size_t size)
+{
+   posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
+   posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), 
*end;
+   int count;
+   struct posix_acl *acl;
+   struct posix_acl_entry *acl_e;
+
+   if (!value)
+   return NULL;
+   if (size < sizeof(posix_acl_xattr_header))
+return ERR_PTR(-EINVAL);
+   if (header->a_version != cpu_to_le32(POSIX_ACL_XATTR_VERSION))
+   return ERR_PTR(-EOPNOTSUPP);
+
+   count = posix_acl_xattr_count(size);
+   if (count < 0)
+   return ERR_PTR(-EINVAL);
+   if (count == 0)
+   return NULL;
+   
+   acl = posix_acl_alloc(count, GFP_NOFS);
+   if (!acl)
+   return ERR_PTR(-ENOMEM);
+   acl_e = acl->a_entries;
+   
+   for (end = entry + count; entry != end; acl_e++, entry++) {
+   acl_e->e_tag  = le16_to_cpu(entry->e_tag);
+   acl_e->e_perm = le16_to_cpu(entry->e_perm);
+
+   switch(acl_e->e_tag) {
+   case ACL_USER_OBJ:
+   case ACL_GROUP_OBJ:
+   case ACL_MASK:
+   case ACL_OTHER:
+  

[PATCH 11/21] hfsplus: use generic posix ACL infrastructure

2013-12-20 Thread Christoph Hellwig
Signed-off-by: Christoph Hellwig 
Reviewed-by: Vyacheslav Dubeyko 
---
 fs/hfsplus/acl.h   |9 +--
 fs/hfsplus/dir.c   |1 +
 fs/hfsplus/inode.c |3 +-
 fs/hfsplus/posix_acl.c |  168 +---
 fs/hfsplus/xattr.c |5 +-
 fs/hfsplus/xattr.h |2 -
 6 files changed, 26 insertions(+), 162 deletions(-)

diff --git a/fs/hfsplus/acl.h b/fs/hfsplus/acl.h
index 07c0d49..95c8ed9 100644
--- a/fs/hfsplus/acl.h
+++ b/fs/hfsplus/acl.h
@@ -12,16 +12,13 @@
 
 /* posix_acl.c */
 struct posix_acl *hfsplus_get_posix_acl(struct inode *inode, int type);
-extern int hfsplus_posix_acl_chmod(struct inode *);
+int hfsplus_set_posix_acl(struct inode *inode, struct posix_acl *acl,
+   int type);
 extern int hfsplus_init_posix_acl(struct inode *, struct inode *);
 
 #else  /* CONFIG_HFSPLUS_FS_POSIX_ACL */
 #define hfsplus_get_posix_acl NULL
-
-static inline int hfsplus_posix_acl_chmod(struct inode *inode)
-{
-   return 0;
-}
+#define hfsplus_set_posix_acl NULL
 
 static inline int hfsplus_init_posix_acl(struct inode *inode, struct inode 
*dir)
 {
diff --git a/fs/hfsplus/dir.c b/fs/hfsplus/dir.c
index 4a4fea0..9ee6298 100644
--- a/fs/hfsplus/dir.c
+++ b/fs/hfsplus/dir.c
@@ -532,6 +532,7 @@ const struct inode_operations hfsplus_dir_inode_operations 
= {
.removexattr= hfsplus_removexattr,
 #ifdef CONFIG_HFSPLUS_FS_POSIX_ACL
.get_acl= hfsplus_get_posix_acl,
+   .set_acl= hfsplus_set_posix_acl,
 #endif
 };
 
diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c
index 37213d0..2e10993 100644
--- a/fs/hfsplus/inode.c
+++ b/fs/hfsplus/inode.c
@@ -319,7 +319,7 @@ static int hfsplus_setattr(struct dentry *dentry, struct 
iattr *attr)
mark_inode_dirty(inode);
 
if (attr->ia_valid & ATTR_MODE) {
-   error = hfsplus_posix_acl_chmod(inode);
+   error = posix_acl_chmod(inode, inode->i_mode);
if (unlikely(error))
return error;
}
@@ -393,6 +393,7 @@ static const struct inode_operations 
hfsplus_file_inode_operations = {
.removexattr= hfsplus_removexattr,
 #ifdef CONFIG_HFSPLUS_FS_POSIX_ACL
.get_acl= hfsplus_get_posix_acl,
+   .set_acl= hfsplus_set_posix_acl,
 #endif
 };
 
diff --git a/fs/hfsplus/posix_acl.c b/fs/hfsplus/posix_acl.c
index 277942f..df0c9af 100644
--- a/fs/hfsplus/posix_acl.c
+++ b/fs/hfsplus/posix_acl.c
@@ -17,9 +17,7 @@ struct posix_acl *hfsplus_get_posix_acl(struct inode *inode, 
int type)
char *value = NULL;
ssize_t size;
 
-   acl = get_cached_acl(inode, type);
-   if (acl != ACL_NOT_CACHED)
-   return acl;
+   hfs_dbg(ACL_MOD, "[%s]: ino %lu\n", __func__, inode->i_ino);
 
switch (type) {
case ACL_TYPE_ACCESS:
@@ -56,17 +54,15 @@ struct posix_acl *hfsplus_get_posix_acl(struct inode 
*inode, int type)
return acl;
 }
 
-static int hfsplus_set_posix_acl(struct inode *inode,
-   int type,
-   struct posix_acl *acl)
+int hfsplus_set_posix_acl(struct inode *inode, struct posix_acl *acl,
+   int type)
 {
int err;
char *xattr_name;
size_t size = 0;
char *value = NULL;
 
-   if (S_ISLNK(inode->i_mode))
-   return -EOPNOTSUPP;
+   hfs_dbg(ACL_MOD, "[%s]: ino %lu\n", __func__, inode->i_ino);
 
switch (type) {
case ACL_TYPE_ACCESS:
@@ -115,7 +111,7 @@ end_set_acl:
 int hfsplus_init_posix_acl(struct inode *inode, struct inode *dir)
 {
int err = 0;
-   struct posix_acl *acl = NULL;
+   struct posix_acl *default_acl, *acl;
 
hfs_dbg(ACL_MOD,
"[%s]: ino %lu, dir->ino %lu\n",
@@ -124,151 +120,21 @@ int hfsplus_init_posix_acl(struct inode *inode, struct 
inode *dir)
if (S_ISLNK(inode->i_mode))
return 0;
 
-   acl = hfsplus_get_posix_acl(dir, ACL_TYPE_DEFAULT);
-   if (IS_ERR(acl))
-   return PTR_ERR(acl);
-
-   if (acl) {
-   if (S_ISDIR(inode->i_mode)) {
-   err = hfsplus_set_posix_acl(inode,
-   ACL_TYPE_DEFAULT,
-   acl);
-   if (unlikely(err))
-   goto init_acl_cleanup;
-   }
-
-   err = __posix_acl_create(&acl, GFP_NOFS, &inode->i_mode);
-   if (unlikely(err < 0))
-   return err;
-
-   if (err > 0)
-   err = hfsplus_set_posix_acl(inode,
-   ACL_TYPE_ACCESS,
-   acl);
-   } else
-   inode->i_mode &= ~current_umask();
-
-init_acl_cleanup:
-   posix_acl_release(acl);
-   return er

[PATCH 13/21] ocfs2: use generic posix ACL infrastructure

2013-12-20 Thread Christoph Hellwig
This contains some major refactoring for the create path so that
inodes are created with the right mode to start with instead of
fixing it up later.

Signed-off-by: Christoph Hellwig 
---
 fs/ocfs2/acl.c  |  234 ++-
 fs/ocfs2/acl.h  |   13 ++-
 fs/ocfs2/file.c |4 +-
 fs/ocfs2/namei.c|   25 -
 fs/ocfs2/refcounttree.c |   19 +++-
 fs/ocfs2/xattr.c|   21 +++--
 fs/ocfs2/xattr.h|6 +-
 7 files changed, 72 insertions(+), 250 deletions(-)

diff --git a/fs/ocfs2/acl.c b/fs/ocfs2/acl.c
index c0f9d2f..555f4cd 100644
--- a/fs/ocfs2/acl.c
+++ b/fs/ocfs2/acl.c
@@ -160,36 +160,6 @@ static struct posix_acl *ocfs2_get_acl_nolock(struct inode 
*inode,
return acl;
 }
 
-
-/*
- * Get posix acl.
- */
-static struct posix_acl *ocfs2_get_acl(struct inode *inode, int type)
-{
-   struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
-   struct buffer_head *di_bh = NULL;
-   struct posix_acl *acl;
-   int ret;
-
-   if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL))
-   return NULL;
-
-   ret = ocfs2_inode_lock(inode, &di_bh, 0);
-   if (ret < 0) {
-   mlog_errno(ret);
-   acl = ERR_PTR(ret);
-   return acl;
-   }
-
-   acl = ocfs2_get_acl_nolock(inode, type, di_bh);
-
-   ocfs2_inode_unlock(inode, 0);
-
-   brelse(di_bh);
-
-   return acl;
-}
-
 /*
  * Helper function to set i_mode in memory and disk. Some call paths
  * will not have di_bh or a journal handle to pass, in which case it
@@ -250,7 +220,7 @@ out:
 /*
  * Set the access or default ACL of an inode.
  */
-static int ocfs2_set_acl(handle_t *handle,
+int ocfs2_set_acl(handle_t *handle,
 struct inode *inode,
 struct buffer_head *di_bh,
 int type,
@@ -313,6 +283,11 @@ static int ocfs2_set_acl(handle_t *handle,
return ret;
 }
 
+int ocfs2_iop_set_acl(struct inode *inode, struct posix_acl *acl, int type)
+{
+   return ocfs2_set_acl(NULL, inode, NULL, type, acl, NULL, NULL);
+}
+
 struct posix_acl *ocfs2_iop_get_acl(struct inode *inode, int type)
 {
struct ocfs2_super *osb;
@@ -334,200 +309,3 @@ struct posix_acl *ocfs2_iop_get_acl(struct inode *inode, 
int type)
 
return acl;
 }
-
-int ocfs2_acl_chmod(struct inode *inode)
-{
-   struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
-   struct posix_acl *acl;
-   int ret;
-
-   if (S_ISLNK(inode->i_mode))
-   return -EOPNOTSUPP;
-
-   if (!(osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL))
-   return 0;
-
-   acl = ocfs2_get_acl(inode, ACL_TYPE_ACCESS);
-   if (IS_ERR(acl) || !acl)
-   return PTR_ERR(acl);
-   ret = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
-   if (ret)
-   return ret;
-   ret = ocfs2_set_acl(NULL, inode, NULL, ACL_TYPE_ACCESS,
-   acl, NULL, NULL);
-   posix_acl_release(acl);
-   return ret;
-}
-
-/*
- * Initialize the ACLs of a new inode. If parent directory has default ACL,
- * then clone to new inode. Called from ocfs2_mknod.
- */
-int ocfs2_init_acl(handle_t *handle,
-  struct inode *inode,
-  struct inode *dir,
-  struct buffer_head *di_bh,
-  struct buffer_head *dir_bh,
-  struct ocfs2_alloc_context *meta_ac,
-  struct ocfs2_alloc_context *data_ac)
-{
-   struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
-   struct posix_acl *acl = NULL;
-   int ret = 0, ret2;
-   umode_t mode;
-
-   if (!S_ISLNK(inode->i_mode)) {
-   if (osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) {
-   acl = ocfs2_get_acl_nolock(dir, ACL_TYPE_DEFAULT,
-  dir_bh);
-   if (IS_ERR(acl))
-   return PTR_ERR(acl);
-   }
-   if (!acl) {
-   mode = inode->i_mode & ~current_umask();
-   ret = ocfs2_acl_set_mode(inode, di_bh, handle, mode);
-   if (ret) {
-   mlog_errno(ret);
-   goto cleanup;
-   }
-   }
-   }
-   if ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) && acl) {
-   if (S_ISDIR(inode->i_mode)) {
-   ret = ocfs2_set_acl(handle, inode, di_bh,
-   ACL_TYPE_DEFAULT, acl,
-   meta_ac, data_ac);
-   if (ret)
-   goto cleanup;
-   }
-   mode = inode->i_mode;
-   ret = __posix_acl_create(&acl, GFP_NOFS, &mode);
-   if (ret < 0)
-   return ret;
-
-   ret2 = ocfs2_acl_set_mode(inode, d

[PATCH 14/21] reiserfs: use generic posix ACL infrastructure

2013-12-20 Thread Christoph Hellwig
Also don't bother to set up a .get_acl method for symlinks as we do not
support access control (ACLs or even mode bits) for symlinks in Linux.

Signed-off-by: Christoph Hellwig 
Reviewed-by: Jan Kara 
---
 fs/reiserfs/acl.h   |4 +-
 fs/reiserfs/file.c  |1 +
 fs/reiserfs/namei.c |4 +-
 fs/reiserfs/xattr.c |5 +-
 fs/reiserfs/xattr_acl.c |  182 +++
 5 files changed, 35 insertions(+), 161 deletions(-)

diff --git a/fs/reiserfs/acl.h b/fs/reiserfs/acl.h
index f096b80..4a211f5 100644
--- a/fs/reiserfs/acl.h
+++ b/fs/reiserfs/acl.h
@@ -48,18 +48,18 @@ static inline int reiserfs_acl_count(size_t size)
 
 #ifdef CONFIG_REISERFS_FS_POSIX_ACL
 struct posix_acl *reiserfs_get_acl(struct inode *inode, int type);
+int reiserfs_set_acl(struct inode *inode, struct posix_acl *acl, int type);
 int reiserfs_acl_chmod(struct inode *inode);
 int reiserfs_inherit_default_acl(struct reiserfs_transaction_handle *th,
 struct inode *dir, struct dentry *dentry,
 struct inode *inode);
 int reiserfs_cache_default_acl(struct inode *dir);
-extern const struct xattr_handler reiserfs_posix_acl_default_handler;
-extern const struct xattr_handler reiserfs_posix_acl_access_handler;
 
 #else
 
 #define reiserfs_cache_default_acl(inode) 0
 #define reiserfs_get_acl NULL
+#define reiserfs_set_acl NULL
 
 static inline int reiserfs_acl_chmod(struct inode *inode)
 {
diff --git a/fs/reiserfs/file.c b/fs/reiserfs/file.c
index dcaafcf..ed58d84 100644
--- a/fs/reiserfs/file.c
+++ b/fs/reiserfs/file.c
@@ -260,4 +260,5 @@ const struct inode_operations 
reiserfs_file_inode_operations = {
.removexattr = reiserfs_removexattr,
.permission = reiserfs_permission,
.get_acl = reiserfs_get_acl,
+   .set_acl = reiserfs_set_acl,
 };
diff --git a/fs/reiserfs/namei.c b/fs/reiserfs/namei.c
index dc5236f..e825f8b 100644
--- a/fs/reiserfs/namei.c
+++ b/fs/reiserfs/namei.c
@@ -1522,6 +1522,7 @@ const struct inode_operations 
reiserfs_dir_inode_operations = {
.removexattr = reiserfs_removexattr,
.permission = reiserfs_permission,
.get_acl = reiserfs_get_acl,
+   .set_acl = reiserfs_set_acl,
 };
 
 /*
@@ -1538,8 +1539,6 @@ const struct inode_operations 
reiserfs_symlink_inode_operations = {
.listxattr = reiserfs_listxattr,
.removexattr = reiserfs_removexattr,
.permission = reiserfs_permission,
-   .get_acl = reiserfs_get_acl,
-
 };
 
 /*
@@ -1553,4 +1552,5 @@ const struct inode_operations 
reiserfs_special_inode_operations = {
.removexattr = reiserfs_removexattr,
.permission = reiserfs_permission,
.get_acl = reiserfs_get_acl,
+   .set_acl = reiserfs_set_acl,
 };
diff --git a/fs/reiserfs/xattr.c b/fs/reiserfs/xattr.c
index 8a9e2dc..5cdfbd6 100644
--- a/fs/reiserfs/xattr.c
+++ b/fs/reiserfs/xattr.c
@@ -50,6 +50,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #define PRIVROOT_NAME ".reiserfs_priv"
 #define XAROOT_NAME   "xattrs"
@@ -904,8 +905,8 @@ static const struct xattr_handler 
*reiserfs_xattr_handlers[] = {
&reiserfs_xattr_security_handler,
 #endif
 #ifdef CONFIG_REISERFS_FS_POSIX_ACL
-   &reiserfs_posix_acl_access_handler,
-   &reiserfs_posix_acl_default_handler,
+   &posix_acl_access_xattr_handler,
+   &posix_acl_default_xattr_handler,
 #endif
NULL
 };
diff --git a/fs/reiserfs/xattr_acl.c b/fs/reiserfs/xattr_acl.c
index d95c959..a6ce532 100644
--- a/fs/reiserfs/xattr_acl.c
+++ b/fs/reiserfs/xattr_acl.c
@@ -11,35 +11,19 @@
 #include "acl.h"
 #include 
 
-static int reiserfs_set_acl(struct reiserfs_transaction_handle *th,
+static int __reiserfs_set_acl(struct reiserfs_transaction_handle *th,
struct inode *inode, int type,
struct posix_acl *acl);
 
-static int
-reiserfs_posix_acl_set(struct dentry *dentry, const char *name, const void 
*value,
-   size_t size, int flags, int type)
+
+int
+reiserfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
 {
-   struct inode *inode = dentry->d_inode;
-   struct posix_acl *acl;
int error, error2;
struct reiserfs_transaction_handle th;
size_t jcreate_blocks;
-   if (!reiserfs_posixacl(inode->i_sb))
-   return -EOPNOTSUPP;
-   if (!inode_owner_or_capable(inode))
-   return -EPERM;
-
-   if (value) {
-   acl = posix_acl_from_xattr(&init_user_ns, value, size);
-   if (IS_ERR(acl)) {
-   return PTR_ERR(acl);
-   } else if (acl) {
-   error = posix_acl_valid(acl);
-   if (error)
-   goto release_and_out;
-   }
-   } else
-   acl = NULL;
+   int size = acl ? posix_acl_xattr_size(acl->a_count) : 0;
+
 
/* Pessimism: We can't assume that anything from

[PATCH 03/21] fs: add get_acl helper

2013-12-20 Thread Christoph Hellwig
Factor out the code to get an ACL either from the inode or disk from
check_acl, so that it can be used elsewhere later on.

Signed-off-by: Christoph Hellwig 
Reviewed-by: Jan Kara 
---
 fs/namei.c|   24 +++-
 fs/posix_acl.c|   26 ++
 include/linux/posix_acl.h |2 ++
 3 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/fs/namei.c b/fs/namei.c
index 3531dee..bcb838e 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -235,27 +235,9 @@ static int check_acl(struct inode *inode, int mask)
return posix_acl_permission(inode, acl, mask & ~MAY_NOT_BLOCK);
}
 
-   acl = get_cached_acl(inode, ACL_TYPE_ACCESS);
-
-   /*
-* A filesystem can force a ACL callback by just never filling the
-* ACL cache. But normally you'd fill the cache either at inode
-* instantiation time, or on the first ->get_acl call.
-*
-* If the filesystem doesn't have a get_acl() function at all, we'll
-* just create the negative cache entry.
-*/
-   if (acl == ACL_NOT_CACHED) {
-   if (inode->i_op->get_acl) {
-   acl = inode->i_op->get_acl(inode, ACL_TYPE_ACCESS);
-   if (IS_ERR(acl))
-   return PTR_ERR(acl);
-   } else {
-   set_cached_acl(inode, ACL_TYPE_ACCESS, NULL);
-   return -EAGAIN;
-   }
-   }
-
+   acl = get_acl(inode, ACL_TYPE_ACCESS);
+   if (IS_ERR(acl))
+   return PTR_ERR(acl);
if (acl) {
int error = posix_acl_permission(inode, acl, mask);
posix_acl_release(acl);
diff --git a/fs/posix_acl.c b/fs/posix_acl.c
index 359d70b..e329c21 100644
--- a/fs/posix_acl.c
+++ b/fs/posix_acl.c
@@ -26,6 +26,32 @@ EXPORT_SYMBOL(posix_acl_valid);
 EXPORT_SYMBOL(posix_acl_equiv_mode);
 EXPORT_SYMBOL(posix_acl_from_mode);
 
+struct posix_acl *get_acl(struct inode *inode, int type)
+{
+   struct posix_acl *acl;
+
+   acl = get_cached_acl(inode, type);
+   if (acl != ACL_NOT_CACHED)
+   return acl;
+
+   if (!IS_POSIXACL(inode))
+   return NULL;
+
+   /*
+* A filesystem can force a ACL callback by just never filling the
+* ACL cache. But normally you'd fill the cache either at inode
+* instantiation time, or on the first ->get_acl call.
+*
+* If the filesystem doesn't have a get_acl() function at all, we'll
+* just create the negative cache entry.
+*/
+   if (!inode->i_op->get_acl) {
+   set_cached_acl(inode, type, NULL);
+   return NULL;
+   }
+   return inode->i_op->get_acl(inode, type);
+}
+
 /*
  * Init a fresh posix_acl
  */
diff --git a/include/linux/posix_acl.h b/include/linux/posix_acl.h
index 7931efe..a8d9918 100644
--- a/include/linux/posix_acl.h
+++ b/include/linux/posix_acl.h
@@ -175,4 +175,6 @@ static inline void cache_no_acl(struct inode *inode)
 #endif
 }
 
+struct posix_acl *get_acl(struct inode *inode, int type);
+
 #endif  /* __LINUX_POSIX_ACL_H */
-- 
1.7.10.4


--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 15/21] xfs: use generic posix ACL infrastructure

2013-12-20 Thread Christoph Hellwig
Also don't bother to set up a .get_acl method for symlinks as we do not
support access control (ACLs or even mode bits) for symlinks in Linux,
and create inodes with the proper mode instead of fixing it up later.

Signed-off-by: Christoph Hellwig 
Reviewed-by: Dave Chinner 
---
 fs/xfs/xfs_acl.c   |  151 +++-
 fs/xfs/xfs_acl.h   |9 +---
 fs/xfs/xfs_iops.c  |   39 +++---
 fs/xfs/xfs_iops.h  |2 +-
 fs/xfs/xfs_xattr.c |4 +-
 5 files changed, 34 insertions(+), 171 deletions(-)

diff --git a/fs/xfs/xfs_acl.c b/fs/xfs/xfs_acl.c
index 057ae2d..0ecec18 100644
--- a/fs/xfs/xfs_acl.c
+++ b/fs/xfs/xfs_acl.c
@@ -124,16 +124,12 @@ struct posix_acl *
 xfs_get_acl(struct inode *inode, int type)
 {
struct xfs_inode *ip = XFS_I(inode);
-   struct posix_acl *acl;
+   struct posix_acl *acl = NULL;
struct xfs_acl *xfs_acl;
unsigned char *ea_name;
int error;
int len;
 
-   acl = get_cached_acl(inode, type);
-   if (acl != ACL_NOT_CACHED)
-   return acl;
-
trace_xfs_get_acl(ip);
 
switch (type) {
@@ -164,10 +160,8 @@ xfs_get_acl(struct inode *inode, int type)
 * cache entry, for any other error assume it is transient and
 * leave the cache entry as ACL_NOT_CACHED.
 */
-   if (error == -ENOATTR) {
-   acl = NULL;
+   if (error == -ENOATTR)
goto out_update_cache;
-   }
goto out;
}
 
@@ -183,15 +177,12 @@ out:
 }
 
 STATIC int
-xfs_set_acl(struct inode *inode, int type, struct posix_acl *acl)
+__xfs_set_acl(struct inode *inode, int type, struct posix_acl *acl)
 {
struct xfs_inode *ip = XFS_I(inode);
unsigned char *ea_name;
int error;
 
-   if (S_ISLNK(inode->i_mode))
-   return -EOPNOTSUPP;
-
switch (type) {
case ACL_TYPE_ACCESS:
ea_name = SGI_ACL_FILE;
@@ -282,131 +273,23 @@ posix_acl_default_exists(struct inode *inode)
return xfs_acl_exists(inode, SGI_ACL_DEFAULT);
 }
 
-/*
- * No need for i_mutex because the inode is not yet exposed to the VFS.
- */
 int
-xfs_inherit_acl(struct inode *inode, struct posix_acl *acl)
+xfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
 {
-   umode_t mode = inode->i_mode;
-   int error = 0, inherit = 0;
-
-   if (S_ISDIR(inode->i_mode)) {
-   error = xfs_set_acl(inode, ACL_TYPE_DEFAULT, acl);
-   if (error)
-   goto out;
-   }
-
-   error = __posix_acl_create(&acl, GFP_KERNEL, &mode);
-   if (error < 0)
-   return error;
-
-   /*
-* If __posix_acl_create returns a positive value we need to
-* inherit a permission that can't be represented using the Unix
-* mode bits and we actually need to set an ACL.
-*/
-   if (error > 0)
-   inherit = 1;
-
-   error = xfs_set_mode(inode, mode);
-   if (error)
-   goto out;
-
-   if (inherit)
-   error = xfs_set_acl(inode, ACL_TYPE_ACCESS, acl);
-
-out:
-   posix_acl_release(acl);
-   return error;
-}
-
-int
-xfs_acl_chmod(struct inode *inode)
-{
-   struct posix_acl *acl;
-   int error;
-
-   if (S_ISLNK(inode->i_mode))
-   return -EOPNOTSUPP;
-
-   acl = xfs_get_acl(inode, ACL_TYPE_ACCESS);
-   if (IS_ERR(acl) || !acl)
-   return PTR_ERR(acl);
-
-   error = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
-   if (error)
-   return error;
-
-   error = xfs_set_acl(inode, ACL_TYPE_ACCESS, acl);
-   posix_acl_release(acl);
-   return error;
-}
-
-static int
-xfs_xattr_acl_get(struct dentry *dentry, const char *name,
-   void *value, size_t size, int type)
-{
-   struct posix_acl *acl;
-   int error;
-
-   acl = xfs_get_acl(dentry->d_inode, type);
-   if (IS_ERR(acl))
-   return PTR_ERR(acl);
-   if (acl == NULL)
-   return -ENODATA;
-
-   error = posix_acl_to_xattr(&init_user_ns, acl, value, size);
-   posix_acl_release(acl);
-
-   return error;
-}
-
-static int
-xfs_xattr_acl_set(struct dentry *dentry, const char *name,
-   const void *value, size_t size, int flags, int type)
-{
-   struct inode *inode = dentry->d_inode;
-   struct posix_acl *acl = NULL;
int error = 0;
 
-   if (flags & XATTR_CREATE)
-   return -EINVAL;
-   if (type == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode))
-   return value ? -EACCES : 0;
-   if (!inode_owner_or_capable(inode))
-   return -EPERM;
-
-   if (!value)
+   if (!acl)
goto set_acl;
 
-   acl = posix_acl_from_xattr(&init_user_ns, value, size);
-   if (!acl) {
-   /*
-* acl_set_file(3) may r

[PATCH 09/21] ext2/3/4: use generic posix ACL infrastructure

2013-12-20 Thread Christoph Hellwig
Signed-off-by: Christoph Hellwig 
Reviewed-by: Jan Kara 
---
 fs/ext2/acl.c   |  188 --
 fs/ext2/acl.h   |8 +-
 fs/ext2/file.c  |1 +
 fs/ext2/inode.c |2 +-
 fs/ext2/namei.c |2 +
 fs/ext2/xattr.c |8 +-
 fs/ext2/xattr.h |2 -
 fs/ext3/acl.c   |  223 ---
 fs/ext3/acl.h   |9 +--
 fs/ext3/file.c  |1 +
 fs/ext3/inode.c |2 +-
 fs/ext3/namei.c |2 +
 fs/ext3/xattr.c |8 +-
 fs/ext3/xattr.h |2 -
 fs/ext4/acl.c   |  223 +++
 fs/ext4/acl.h   |9 +--
 fs/ext4/file.c  |1 +
 fs/ext4/inode.c |2 +-
 fs/ext4/namei.c |2 +
 fs/ext4/xattr.c |8 +-
 fs/ext4/xattr.h |2 -
 21 files changed, 100 insertions(+), 605 deletions(-)

diff --git a/fs/ext2/acl.c b/fs/ext2/acl.c
index 6e842a7..1b8001b 100644
--- a/fs/ext2/acl.c
+++ b/fs/ext2/acl.c
@@ -148,13 +148,6 @@ ext2_get_acl(struct inode *inode, int type)
struct posix_acl *acl;
int retval;
 
-   if (!test_opt(inode->i_sb, POSIX_ACL))
-   return NULL;
-
-   acl = get_cached_acl(inode, type);
-   if (acl != ACL_NOT_CACHED)
-   return acl;
-
switch (type) {
case ACL_TYPE_ACCESS:
name_index = EXT2_XATTR_INDEX_POSIX_ACL_ACCESS;
@@ -189,19 +182,14 @@ ext2_get_acl(struct inode *inode, int type)
 /*
  * inode->i_mutex: down
  */
-static int
-ext2_set_acl(struct inode *inode, int type, struct posix_acl *acl)
+int
+ext2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
 {
int name_index;
void *value = NULL;
size_t size = 0;
int error;
 
-   if (S_ISLNK(inode->i_mode))
-   return -EOPNOTSUPP;
-   if (!test_opt(inode->i_sb, POSIX_ACL))
-   return 0;
-
switch(type) {
case ACL_TYPE_ACCESS:
name_index = EXT2_XATTR_INDEX_POSIX_ACL_ACCESS;
@@ -250,169 +238,21 @@ ext2_set_acl(struct inode *inode, int type, struct 
posix_acl *acl)
 int
 ext2_init_acl(struct inode *inode, struct inode *dir)
 {
-   struct posix_acl *acl = NULL;
-   int error = 0;
-
-   if (!S_ISLNK(inode->i_mode)) {
-   if (test_opt(dir->i_sb, POSIX_ACL)) {
-   acl = ext2_get_acl(dir, ACL_TYPE_DEFAULT);
-   if (IS_ERR(acl))
-   return PTR_ERR(acl);
-   }
-   if (!acl)
-   inode->i_mode &= ~current_umask();
-   }
-   if (test_opt(inode->i_sb, POSIX_ACL) && acl) {
-   if (S_ISDIR(inode->i_mode)) {
-   error = ext2_set_acl(inode, ACL_TYPE_DEFAULT, acl);
-   if (error)
-   goto cleanup;
-   }
-   error = __posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
-   if (error < 0)
-   return error;
-   if (error > 0) {
-   /* This is an extended ACL */
-   error = ext2_set_acl(inode, ACL_TYPE_ACCESS, acl);
-   }
-   }
-cleanup:
-   posix_acl_release(acl);
-   return error;
-}
-
-/*
- * Does chmod for an inode that may have an Access Control List. The
- * inode->i_mode field must be updated to the desired value by the caller
- * before calling this function.
- * Returns 0 on success, or a negative error number.
- *
- * We change the ACL rather than storing some ACL entries in the file
- * mode permission bits (which would be more efficient), because that
- * would break once additional permissions (like  ACL_APPEND, ACL_DELETE
- * for directories) are added. There are no more bits available in the
- * file mode.
- *
- * inode->i_mutex: down
- */
-int
-ext2_acl_chmod(struct inode *inode)
-{
-   struct posix_acl *acl;
-int error;
+   struct posix_acl *default_acl, *acl;
+   int error;
 
-   if (!test_opt(inode->i_sb, POSIX_ACL))
-   return 0;
-   if (S_ISLNK(inode->i_mode))
-   return -EOPNOTSUPP;
-   acl = ext2_get_acl(inode, ACL_TYPE_ACCESS);
-   if (IS_ERR(acl) || !acl)
-   return PTR_ERR(acl);
-   error = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
+   error = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
if (error)
return error;
-   error = ext2_set_acl(inode, ACL_TYPE_ACCESS, acl);
-   posix_acl_release(acl);
-   return error;
-}
 
-/*
- * Extended attribut handlers
- */
-static size_t
-ext2_xattr_list_acl_access(struct dentry *dentry, char *list, size_t list_size,
-  const char *name, size_t name_len, int type)
-{
-   const size_t size = sizeof(POSIX_ACL_XATTR_ACCESS);
-
-   if (!test_opt(dentry->d_sb, POSIX_ACL))
-   return 0;
-   if (list && size <= list_size)
-   memcpy(list, POSIX

[PATCH 10/21] f2fs: use generic posix ACL infrastructure

2013-12-20 Thread Christoph Hellwig
f2fs has some weird mode bit handling, so still using the old
chmod code for now.

Signed-off-by: Christoph Hellwig 
Reviewed-by: Jaegeuk Kim 
---
 fs/f2fs/acl.c   |  174 ++-
 fs/f2fs/acl.h   |7 +--
 fs/f2fs/f2fs.h  |4 ++
 fs/f2fs/file.c  |3 +-
 fs/f2fs/namei.c |2 +
 fs/f2fs/xattr.c |9 +--
 fs/f2fs/xattr.h |2 -
 7 files changed, 31 insertions(+), 170 deletions(-)

diff --git a/fs/f2fs/acl.c b/fs/f2fs/acl.c
index 45e8430..fa8da4c 100644
--- a/fs/f2fs/acl.c
+++ b/fs/f2fs/acl.c
@@ -17,9 +17,6 @@
 #include "xattr.h"
 #include "acl.h"
 
-#define get_inode_mode(i)  ((is_inode_flag_set(F2FS_I(i), FI_ACL_MODE)) ? \
-   (F2FS_I(i)->i_acl_mode) : ((i)->i_mode))
-
 static inline size_t f2fs_acl_size(int count)
 {
if (count <= 4) {
@@ -167,19 +164,11 @@ fail:
 
 struct posix_acl *f2fs_get_acl(struct inode *inode, int type)
 {
-   struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
int name_index = F2FS_XATTR_INDEX_POSIX_ACL_DEFAULT;
void *value = NULL;
struct posix_acl *acl;
int retval;
 
-   if (!test_opt(sbi, POSIX_ACL))
-   return NULL;
-
-   acl = get_cached_acl(inode, type);
-   if (acl != ACL_NOT_CACHED)
-   return acl;
-
if (type == ACL_TYPE_ACCESS)
name_index = F2FS_XATTR_INDEX_POSIX_ACL_ACCESS;
 
@@ -205,21 +194,15 @@ struct posix_acl *f2fs_get_acl(struct inode *inode, int 
type)
return acl;
 }
 
-static int f2fs_set_acl(struct inode *inode, int type,
+static int __f2fs_set_acl(struct inode *inode, int type,
struct posix_acl *acl, struct page *ipage)
 {
-   struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
struct f2fs_inode_info *fi = F2FS_I(inode);
int name_index;
void *value = NULL;
size_t size = 0;
int error;
 
-   if (!test_opt(sbi, POSIX_ACL))
-   return 0;
-   if (S_ISLNK(inode->i_mode))
-   return -EOPNOTSUPP;
-
switch (type) {
case ACL_TYPE_ACCESS:
name_index = F2FS_XATTR_INDEX_POSIX_ACL_ACCESS;
@@ -261,154 +244,31 @@ static int f2fs_set_acl(struct inode *inode, int type,
return error;
 }
 
-int f2fs_init_acl(struct inode *inode, struct inode *dir, struct page *ipage)
+int f2fs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
 {
-   struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb);
-   struct posix_acl *acl = NULL;
-   int error = 0;
-
-   if (!S_ISLNK(inode->i_mode)) {
-   if (test_opt(sbi, POSIX_ACL)) {
-   acl = f2fs_get_acl(dir, ACL_TYPE_DEFAULT);
-   if (IS_ERR(acl))
-   return PTR_ERR(acl);
-   }
-   if (!acl)
-   inode->i_mode &= ~current_umask();
-   }
-
-   if (!test_opt(sbi, POSIX_ACL) || !acl)
-   goto cleanup;
-
-   if (S_ISDIR(inode->i_mode)) {
-   error = f2fs_set_acl(inode, ACL_TYPE_DEFAULT, acl, ipage);
-   if (error)
-   goto cleanup;
-   }
-   error = __posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
-   if (error < 0)
-   return error;
-   if (error > 0)
-   error = f2fs_set_acl(inode, ACL_TYPE_ACCESS, acl, ipage);
-cleanup:
-   posix_acl_release(acl);
-   return error;
+   return __f2fs_set_acl(inode, type, acl, NULL);
 }
 
-int f2fs_acl_chmod(struct inode *inode)
+int f2fs_init_acl(struct inode *inode, struct inode *dir, struct page *ipage)
 {
-   struct f2fs_sb_info *sbi = F2FS_SB(inode->i_sb);
-   struct posix_acl *acl;
-   int error;
-   umode_t mode = get_inode_mode(inode);
-
-   if (!test_opt(sbi, POSIX_ACL))
-   return 0;
-   if (S_ISLNK(mode))
-   return -EOPNOTSUPP;
-
-   acl = f2fs_get_acl(inode, ACL_TYPE_ACCESS);
-   if (IS_ERR(acl) || !acl)
-   return PTR_ERR(acl);
+   struct posix_acl *default_acl, *acl;
+   int error = 0;
 
-   error = __posix_acl_chmod(&acl, GFP_KERNEL, mode);
+   error = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
if (error)
return error;
 
-   error = f2fs_set_acl(inode, ACL_TYPE_ACCESS, acl, NULL);
-   posix_acl_release(acl);
-   return error;
-}
-
-static size_t f2fs_xattr_list_acl(struct dentry *dentry, char *list,
-   size_t list_size, const char *name, size_t name_len, int type)
-{
-   struct f2fs_sb_info *sbi = F2FS_SB(dentry->d_sb);
-   const char *xname = POSIX_ACL_XATTR_DEFAULT;
-   size_t size;
-
-   if (!test_opt(sbi, POSIX_ACL))
-   return 0;
-
-   if (type == ACL_TYPE_ACCESS)
-   xname = POSIX_ACL_XATTR_ACCESS;
-
-   size = strlen(xname) + 1;
-   if (list && size <= list_size)
-   memcpy(list, xname, si

[PATCH 12/21] jffs2: use generic posix ACL infrastructure

2013-12-20 Thread Christoph Hellwig
Also don't bother to set up a .get_acl method for symlinks as we do not
support access control (ACLs or even mode bits) for symlinks in Linux.

Signed-off-by: Christoph Hellwig 
---
 fs/jffs2/acl.c |  141 
 fs/jffs2/acl.h |7 +--
 fs/jffs2/dir.c |1 +
 fs/jffs2/file.c|1 +
 fs/jffs2/fs.c  |7 +--
 fs/jffs2/symlink.c |1 -
 fs/jffs2/xattr.c   |9 ++--
 7 files changed, 24 insertions(+), 143 deletions(-)

diff --git a/fs/jffs2/acl.c b/fs/jffs2/acl.c
index 4d6e31b..009ec0b 100644
--- a/fs/jffs2/acl.c
+++ b/fs/jffs2/acl.c
@@ -178,10 +178,6 @@ struct posix_acl *jffs2_get_acl(struct inode *inode, int 
type)
char *value = NULL;
int rc, xprefix;
 
-   acl = get_cached_acl(inode, type);
-   if (acl != ACL_NOT_CACHED)
-   return acl;
-
switch (type) {
case ACL_TYPE_ACCESS:
xprefix = JFFS2_XPREFIX_ACL_ACCESS;
@@ -232,13 +228,10 @@ static int __jffs2_set_acl(struct inode *inode, int 
xprefix, struct posix_acl *a
return rc;
 }
 
-static int jffs2_set_acl(struct inode *inode, int type, struct posix_acl *acl)
+int jffs2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
 {
int rc, xprefix;
 
-   if (S_ISLNK(inode->i_mode))
-   return -EOPNOTSUPP;
-
switch (type) {
case ACL_TYPE_ACCESS:
xprefix = JFFS2_XPREFIX_ACL_ACCESS;
@@ -277,30 +270,21 @@ static int jffs2_set_acl(struct inode *inode, int type, 
struct posix_acl *acl)
 
 int jffs2_init_acl_pre(struct inode *dir_i, struct inode *inode, umode_t 
*i_mode)
 {
-   struct posix_acl *acl;
+   struct posix_acl *default_acl, *acl;
int rc;
 
cache_no_acl(inode);
 
-   if (S_ISLNK(*i_mode))
-   return 0;   /* Symlink always has no-ACL */
-
-   acl = jffs2_get_acl(dir_i, ACL_TYPE_DEFAULT);
-   if (IS_ERR(acl))
-   return PTR_ERR(acl);
-
-   if (!acl) {
-   *i_mode &= ~current_umask();
-   } else {
-   if (S_ISDIR(*i_mode))
-   set_cached_acl(inode, ACL_TYPE_DEFAULT, acl);
-
-   rc = __posix_acl_create(&acl, GFP_KERNEL, i_mode);
-   if (rc < 0)
-   return rc;
-   if (rc > 0)
-   set_cached_acl(inode, ACL_TYPE_ACCESS, acl);
+   rc = posix_acl_create(dir_i, i_mode, &default_acl, &acl);
+   if (rc)
+   return rc;
 
+   if (default_acl) {
+   set_cached_acl(inode, ACL_TYPE_DEFAULT, default_acl);
+   posix_acl_release(default_acl);
+   }
+   if (acl) {
+   set_cached_acl(inode, ACL_TYPE_ACCESS, acl);
posix_acl_release(acl);
}
return 0;
@@ -324,106 +308,3 @@ int jffs2_init_acl_post(struct inode *inode)
 
return 0;
 }
-
-int jffs2_acl_chmod(struct inode *inode)
-{
-   struct posix_acl *acl;
-   int rc;
-
-   if (S_ISLNK(inode->i_mode))
-   return -EOPNOTSUPP;
-   acl = jffs2_get_acl(inode, ACL_TYPE_ACCESS);
-   if (IS_ERR(acl) || !acl)
-   return PTR_ERR(acl);
-   rc = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
-   if (rc)
-   return rc;
-   rc = jffs2_set_acl(inode, ACL_TYPE_ACCESS, acl);
-   posix_acl_release(acl);
-   return rc;
-}
-
-static size_t jffs2_acl_access_listxattr(struct dentry *dentry, char *list,
-   size_t list_size, const char *name, size_t name_len, int type)
-{
-   const int retlen = sizeof(POSIX_ACL_XATTR_ACCESS);
-
-   if (list && retlen <= list_size)
-   strcpy(list, POSIX_ACL_XATTR_ACCESS);
-   return retlen;
-}
-
-static size_t jffs2_acl_default_listxattr(struct dentry *dentry, char *list,
-   size_t list_size, const char *name, size_t name_len, int type)
-{
-   const int retlen = sizeof(POSIX_ACL_XATTR_DEFAULT);
-
-   if (list && retlen <= list_size)
-   strcpy(list, POSIX_ACL_XATTR_DEFAULT);
-   return retlen;
-}
-
-static int jffs2_acl_getxattr(struct dentry *dentry, const char *name,
-   void *buffer, size_t size, int type)
-{
-   struct posix_acl *acl;
-   int rc;
-
-   if (name[0] != '\0')
-   return -EINVAL;
-
-   acl = jffs2_get_acl(dentry->d_inode, type);
-   if (IS_ERR(acl))
-   return PTR_ERR(acl);
-   if (!acl)
-   return -ENODATA;
-   rc = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
-   posix_acl_release(acl);
-
-   return rc;
-}
-
-static int jffs2_acl_setxattr(struct dentry *dentry, const char *name,
-   const void *value, size_t size, int flags, int type)
-{
-   struct posix_acl *acl;
-   int rc;
-
-   if (name[0] != '\0')
-   return -EINVAL;
-   if (!inode_owner_or_capable(dentry->d_inode))
-   return -EPERM;
-
-   if (val

[PATCH 20/21] nfsd: use get_acl and ->set_acl

2013-12-20 Thread Christoph Hellwig
Remove the boilerplate code to marshall and unmarhall ACL objects into
xattrs and operate on the posix_acl objects directly.  Also move all
the ACL handling code into nfs?acl.c where it belongs.

Signed-off-by: Christoph Hellwig 
---
 fs/nfsd/acl.h  |   16 ++--
 fs/nfsd/nfs2acl.c  |   72 +---
 fs/nfsd/nfs3acl.c  |   62 +++---
 fs/nfsd/nfs4acl.c  |  120 --
 fs/nfsd/nfs4proc.c |1 +
 fs/nfsd/vfs.c  |  241 
 fs/nfsd/vfs.h  |8 --
 7 files changed, 173 insertions(+), 347 deletions(-)

diff --git a/fs/nfsd/acl.h b/fs/nfsd/acl.h
index 8b186a4..8b68218 100644
--- a/fs/nfsd/acl.h
+++ b/fs/nfsd/acl.h
@@ -35,7 +35,9 @@
 #ifndef LINUX_NFS4_ACL_H
 #define LINUX_NFS4_ACL_H
 
-#include 
+struct nfs4_acl;
+struct svc_fh;
+struct svc_rqst;
 
 /* Maximum ACL we'll accept from client; chosen (somewhat arbitrarily) to
  * fit in a page: */
@@ -45,13 +47,9 @@ struct nfs4_acl *nfs4_acl_new(int);
 int nfs4_acl_get_whotype(char *, u32);
 int nfs4_acl_write_who(int who, char *p);
 
-#define NFS4_ACL_TYPE_DEFAULT  0x01
-#define NFS4_ACL_DIR   0x02
-#define NFS4_ACL_OWNER 0x04
-
-struct nfs4_acl *nfs4_acl_posix_to_nfsv4(struct posix_acl *,
-   struct posix_acl *, unsigned int flags);
-int nfs4_acl_nfsv4_to_posix(struct nfs4_acl *, struct posix_acl **,
-   struct posix_acl **, unsigned int flags);
+int nfsd4_get_nfs4_acl(struct svc_rqst *rqstp, struct dentry *dentry,
+   struct nfs4_acl **acl);
+__be32 nfsd4_set_nfs4_acl(struct svc_rqst *rqstp, struct svc_fh *fhp,
+   struct nfs4_acl *acl);
 
 #endif /* LINUX_NFS4_ACL_H */
diff --git a/fs/nfsd/nfs2acl.c b/fs/nfsd/nfs2acl.c
index 95d76dc..11c1fba 100644
--- a/fs/nfsd/nfs2acl.c
+++ b/fs/nfsd/nfs2acl.c
@@ -30,8 +30,9 @@ nfsacld_proc_null(struct svc_rqst *rqstp, void *argp, void 
*resp)
 static __be32 nfsacld_proc_getacl(struct svc_rqst * rqstp,
struct nfsd3_getaclargs *argp, struct nfsd3_getaclres *resp)
 {
-   svc_fh *fh;
struct posix_acl *acl;
+   struct inode *inode;
+   svc_fh *fh;
__be32 nfserr = 0;
 
dprintk("nfsd: GETACL(2acl)   %s\n", SVCFH_fmt(&argp->fh));
@@ -41,6 +42,8 @@ static __be32 nfsacld_proc_getacl(struct svc_rqst * rqstp,
if (nfserr)
RETURN_STATUS(nfserr);
 
+   inode = fh->fh_dentry->d_inode;
+
if (argp->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT))
RETURN_STATUS(nfserr_inval);
resp->mask = argp->mask;
@@ -50,21 +53,13 @@ static __be32 nfsacld_proc_getacl(struct svc_rqst * rqstp,
goto fail;
 
if (resp->mask & (NFS_ACL|NFS_ACLCNT)) {
-   acl = nfsd_get_posix_acl(fh, ACL_TYPE_ACCESS);
+   acl = get_acl(inode, ACL_TYPE_ACCESS);
if (IS_ERR(acl)) {
-   int err = PTR_ERR(acl);
-
-   if (err == -ENODATA || err == -EOPNOTSUPP)
-   acl = NULL;
-   else {
-   nfserr = nfserrno(err);
-   goto fail;
-   }
+   nfserr = nfserrno(PTR_ERR(acl));
+   goto fail;
}
if (acl == NULL) {
/* Solaris returns the inode's minimum ACL. */
-
-   struct inode *inode = fh->fh_dentry->d_inode;
acl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
}
resp->acl_access = acl;
@@ -72,17 +67,10 @@ static __be32 nfsacld_proc_getacl(struct svc_rqst * rqstp,
if (resp->mask & (NFS_DFACL|NFS_DFACLCNT)) {
/* Check how Solaris handles requests for the Default ACL
   of a non-directory! */
-
-   acl = nfsd_get_posix_acl(fh, ACL_TYPE_DEFAULT);
+   acl = get_acl(inode, ACL_TYPE_DEFAULT);
if (IS_ERR(acl)) {
-   int err = PTR_ERR(acl);
-
-   if (err == -ENODATA || err == -EOPNOTSUPP)
-   acl = NULL;
-   else {
-   nfserr = nfserrno(err);
-   goto fail;
-   }
+   nfserr = nfserrno(PTR_ERR(acl));
+   goto fail;
}
resp->acl_default = acl;
}
@@ -103,31 +91,51 @@ static __be32 nfsacld_proc_setacl(struct svc_rqst * rqstp,
struct nfsd3_setaclargs *argp,
struct nfsd_attrstat *resp)
 {
+   struct inode *inode;
svc_fh *fh;
__be32 nfserr = 0;
+   int error;
 
dprintk("nfsd: SETACL(2acl)   %s\n", SVCFH_fmt(&argp->fh));
 
fh = fh_copy(&resp->fh, &argp->fh);
nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_SATTR);
+  

[PATCH 16/21] jfs: use generic posix ACL infrastructure

2013-12-20 Thread Christoph Hellwig
Copy the scheme I introduced to btrfs many years ago to only use the
xattr handler for ACLs, but pass plain attrs straight through.

Signed-off-by: Christoph Hellwig 
Reviewed-by: Dave Kleikamp 
---
 fs/jfs/acl.c   |  105 --
 fs/jfs/file.c  |4 +-
 fs/jfs/jfs_acl.h   |7 +---
 fs/jfs/jfs_xattr.h |2 +
 fs/jfs/namei.c |1 +
 fs/jfs/super.c |2 +
 fs/jfs/xattr.c |  108 ++--
 7 files changed, 89 insertions(+), 140 deletions(-)

diff --git a/fs/jfs/acl.c b/fs/jfs/acl.c
index 28d529a..e973b85 100644
--- a/fs/jfs/acl.c
+++ b/fs/jfs/acl.c
@@ -72,7 +72,7 @@ struct posix_acl *jfs_get_acl(struct inode *inode, int type)
return acl;
 }
 
-static int jfs_set_acl(tid_t tid, struct inode *inode, int type,
+static int __jfs_set_acl(tid_t tid, struct inode *inode, int type,
   struct posix_acl *acl)
 {
char *ea_name;
@@ -80,21 +80,22 @@ static int jfs_set_acl(tid_t tid, struct inode *inode, int 
type,
int size = 0;
char *value = NULL;
 
-   if (S_ISLNK(inode->i_mode))
-   return -EOPNOTSUPP;
-
-   switch(type) {
-   case ACL_TYPE_ACCESS:
-   ea_name = POSIX_ACL_XATTR_ACCESS;
-   break;
-   case ACL_TYPE_DEFAULT:
-   ea_name = POSIX_ACL_XATTR_DEFAULT;
-   if (!S_ISDIR(inode->i_mode))
-   return acl ? -EACCES : 0;
-   break;
-   default:
-   return -EINVAL;
+   switch (type) {
+   case ACL_TYPE_ACCESS:
+   ea_name = POSIX_ACL_XATTR_ACCESS;
+   rc = posix_acl_equiv_mode(acl, &inode->i_mode);
+   if (rc < 0)
+   return rc;
+   if (rc == 0)
+   acl = NULL;
+   break;
+   case ACL_TYPE_DEFAULT:
+   ea_name = POSIX_ACL_XATTR_DEFAULT;
+   break;
+   default:
+   return -EINVAL;
}
+
if (acl) {
size = posix_acl_xattr_size(acl->a_count);
value = kmalloc(size, GFP_KERNEL);
@@ -114,65 +115,43 @@ out:
return rc;
 }
 
+int jfs_set_acl(struct inode *inode, struct posix_acl *acl, int type)
+{
+   int rc;
+   tid_t tid;
+
+   tid = txBegin(inode->i_sb, 0);
+   mutex_lock(&JFS_IP(inode)->commit_mutex);
+   rc = __jfs_set_acl(tid, inode, type, acl);
+   if (!rc)
+   rc = txCommit(tid, 1, &inode, 0);
+   txEnd(tid);
+   mutex_unlock(&JFS_IP(inode)->commit_mutex);
+   return rc;
+}
+
 int jfs_init_acl(tid_t tid, struct inode *inode, struct inode *dir)
 {
-   struct posix_acl *acl = NULL;
+   struct posix_acl *default_acl, *acl;
int rc = 0;
 
-   if (S_ISLNK(inode->i_mode))
-   return 0;
+   rc = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
+   if (rc)
+   return rc;
 
-   acl = jfs_get_acl(dir, ACL_TYPE_DEFAULT);
-   if (IS_ERR(acl))
-   return PTR_ERR(acl);
+   if (default_acl) {
+   rc = __jfs_set_acl(tid, inode, ACL_TYPE_DEFAULT, default_acl);
+   posix_acl_release(default_acl);
+   }
 
if (acl) {
-   if (S_ISDIR(inode->i_mode)) {
-   rc = jfs_set_acl(tid, inode, ACL_TYPE_DEFAULT, acl);
-   if (rc)
-   goto cleanup;
-   }
-   rc = __posix_acl_create(&acl, GFP_KERNEL, &inode->i_mode);
-   if (rc < 0)
-   goto cleanup; /* posix_acl_release(NULL) is no-op */
-   if (rc > 0)
-   rc = jfs_set_acl(tid, inode, ACL_TYPE_ACCESS, acl);
-cleanup:
+   if (!rc)
+   rc = __jfs_set_acl(tid, inode, ACL_TYPE_ACCESS, acl);
posix_acl_release(acl);
-   } else
-   inode->i_mode &= ~current_umask();
+   }
 
JFS_IP(inode)->mode2 = (JFS_IP(inode)->mode2 & 0x) |
   inode->i_mode;
 
return rc;
 }
-
-int jfs_acl_chmod(struct inode *inode)
-{
-   struct posix_acl *acl;
-   int rc;
-   tid_t tid;
-
-   if (S_ISLNK(inode->i_mode))
-   return -EOPNOTSUPP;
-
-   acl = jfs_get_acl(inode, ACL_TYPE_ACCESS);
-   if (IS_ERR(acl) || !acl)
-   return PTR_ERR(acl);
-
-   rc = __posix_acl_chmod(&acl, GFP_KERNEL, inode->i_mode);
-   if (rc)
-   return rc;
-
-   tid = txBegin(inode->i_sb, 0);
-   mutex_lock(&JFS_IP(inode)->commit_mutex);
-   rc = jfs_set_acl(tid, inode, ACL_TYPE_ACCESS, acl);
-   if (!rc)
-   rc = txCommit(tid, 1, &inode, 0);
-   txEnd(tid);
-   mutex_unlock(&JFS_IP(inode)->commit_mutex);
-
-   posix_acl_release(acl);
- 

[PATCH 21/21] hfsplus: remove can_set_xattr

2013-12-20 Thread Christoph Hellwig
When using the per-superblock xattr handlers permission checking is
done by the generic code.  hfsplus just needs to check for the magic
osx attribute not to leak into protected namespaces.

Also given that the code was obviously copied from JFS the proper
attribution was missing.

Signed-off-by: Christoph Hellwig 
---
 fs/hfsplus/xattr.c |   87 ++--
 1 file changed, 3 insertions(+), 84 deletions(-)

diff --git a/fs/hfsplus/xattr.c b/fs/hfsplus/xattr.c
index bf88baa..0b4a5c9 100644
--- a/fs/hfsplus/xattr.c
+++ b/fs/hfsplus/xattr.c
@@ -52,82 +52,6 @@ static inline int is_known_namespace(const char *name)
return true;
 }
 
-static int can_set_system_xattr(struct inode *inode, const char *name,
-   const void *value, size_t size)
-{
-#ifdef CONFIG_HFSPLUS_FS_POSIX_ACL
-   struct posix_acl *acl;
-   int err;
-
-   if (!inode_owner_or_capable(inode))
-   return -EPERM;
-
-   /*
-* POSIX_ACL_XATTR_ACCESS is tied to i_mode
-*/
-   if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0) {
-   acl = posix_acl_from_xattr(&init_user_ns, value, size);
-   if (IS_ERR(acl))
-   return PTR_ERR(acl);
-   if (acl) {
-   err = posix_acl_equiv_mode(acl, &inode->i_mode);
-   posix_acl_release(acl);
-   if (err < 0)
-   return err;
-   mark_inode_dirty(inode);
-   }
-   /*
-* We're changing the ACL.  Get rid of the cached one
-*/
-   forget_cached_acl(inode, ACL_TYPE_ACCESS);
-
-   return 0;
-   } else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0) {
-   acl = posix_acl_from_xattr(&init_user_ns, value, size);
-   if (IS_ERR(acl))
-   return PTR_ERR(acl);
-   posix_acl_release(acl);
-
-   /*
-* We're changing the default ACL.  Get rid of the cached one
-*/
-   forget_cached_acl(inode, ACL_TYPE_DEFAULT);
-
-   return 0;
-   }
-#endif /* CONFIG_HFSPLUS_FS_POSIX_ACL */
-   return -EOPNOTSUPP;
-}
-
-static int can_set_xattr(struct inode *inode, const char *name,
-   const void *value, size_t value_len)
-{
-   if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
-   return can_set_system_xattr(inode, name, value, value_len);
-
-   if (!strncmp(name, XATTR_MAC_OSX_PREFIX, XATTR_MAC_OSX_PREFIX_LEN)) {
-   /*
-* This makes sure that we aren't trying to set an
-* attribute in a different namespace by prefixing it
-* with "osx."
-*/
-   if (is_known_namespace(name + XATTR_MAC_OSX_PREFIX_LEN))
-   return -EOPNOTSUPP;
-
-   return 0;
-   }
-
-   /*
-* Don't allow setting an attribute in an unknown namespace.
-*/
-   if (strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) &&
-   strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) &&
-   strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN))
-   return -EOPNOTSUPP;
-
-   return 0;
-}
-
 static void hfsplus_init_header_node(struct inode *attr_file,
u32 clump_size,
char *buf, u16 node_size)
@@ -350,10 +274,6 @@ int __hfsplus_setxattr(struct inode *inode, const char 
*name,
HFSPLUS_IS_RSRC(inode))
return -EOPNOTSUPP;
 
-   err = can_set_xattr(inode, name, value, size);
-   if (err)
-   return err;
-
if (strncmp(name, XATTR_MAC_OSX_PREFIX,
XATTR_MAC_OSX_PREFIX_LEN) == 0)
name += XATTR_MAC_OSX_PREFIX_LEN;
@@ -841,10 +761,6 @@ int hfsplus_removexattr(struct dentry *dentry, const char 
*name)
if (!HFSPLUS_SB(inode->i_sb)->attr_tree)
return -EOPNOTSUPP;
 
-   err = can_set_xattr(inode, name, NULL, 0);
-   if (err)
-   return err;
-
if (strncmp(name, XATTR_MAC_OSX_PREFIX,
XATTR_MAC_OSX_PREFIX_LEN) == 0)
name += XATTR_MAC_OSX_PREFIX_LEN;
@@ -941,6 +857,9 @@ static int hfsplus_osx_setxattr(struct dentry *dentry, 
const char *name,
if (len > HFSPLUS_ATTR_MAX_STRLEN)
return -EOPNOTSUPP;
 
+   if (is_known_namespace(name))
+   return -EOPNOTSUPP;
+
strcpy(xattr_name, XATTR_MAC_OSX_PREFIX);
strcpy(xattr_name + XATTR_MAC_OSX_PREFIX_LEN, name);
 
-- 
1.7.10.4


--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo

[PATCH 18/21] nfs: use generic posix ACL infrastructure for v3 Posix ACLs

2013-12-20 Thread Christoph Hellwig
This causes a small behaviour change in that we don't bother to set
ACLs on file creation if the mode bit can express the access permissions
fully, and thus behaving identical to local filesystems.

Signed-off-by: Christoph Hellwig 
---
 fs/nfs/inode.c |4 -
 fs/nfs/nfs3acl.c   |  291 +---
 fs/nfs/nfs3proc.c  |   76 +
 fs/nfs/nfs3super.c |3 +
 include/linux/nfs_fs.h |   24 ++--
 5 files changed, 117 insertions(+), 281 deletions(-)

diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 00ad1c2..ecd11ba 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -1641,10 +1641,6 @@ struct inode *nfs_alloc_inode(struct super_block *sb)
return NULL;
nfsi->flags = 0UL;
nfsi->cache_validity = 0UL;
-#ifdef CONFIG_NFS_V3_ACL
-   nfsi->acl_access = ERR_PTR(-EAGAIN);
-   nfsi->acl_default = ERR_PTR(-EAGAIN);
-#endif
 #if IS_ENABLED(CONFIG_NFS_V4)
nfsi->nfs4_acl = NULL;
 #endif /* CONFIG_NFS_V4 */
diff --git a/fs/nfs/nfs3acl.c b/fs/nfs/nfs3acl.c
index e859675..9a5ca03 100644
--- a/fs/nfs/nfs3acl.c
+++ b/fs/nfs/nfs3acl.c
@@ -10,179 +10,7 @@
 
 #define NFSDBG_FACILITYNFSDBG_PROC
 
-ssize_t nfs3_listxattr(struct dentry *dentry, char *buffer, size_t size)
-{
-   struct inode *inode = dentry->d_inode;
-   struct posix_acl *acl;
-   int pos=0, len=0;
-
-#  define output(s) do {   \
-   if (pos + sizeof(s) <= size) {  \
-   memcpy(buffer + pos, s, sizeof(s)); \
-   pos += sizeof(s);   \
-   }   \
-   len += sizeof(s);   \
-   } while(0)
-
-   acl = nfs3_proc_getacl(inode, ACL_TYPE_ACCESS);
-   if (IS_ERR(acl))
-   return PTR_ERR(acl);
-   if (acl) {
-   output("system.posix_acl_access");
-   posix_acl_release(acl);
-   }
-
-   if (S_ISDIR(inode->i_mode)) {
-   acl = nfs3_proc_getacl(inode, ACL_TYPE_DEFAULT);
-   if (IS_ERR(acl))
-   return PTR_ERR(acl);
-   if (acl) {
-   output("system.posix_acl_default");
-   posix_acl_release(acl);
-   }
-   }
-
-#  undef output
-
-   if (!buffer || len <= size)
-   return len;
-   return -ERANGE;
-}
-
-ssize_t nfs3_getxattr(struct dentry *dentry, const char *name,
-   void *buffer, size_t size)
-{
-   struct inode *inode = dentry->d_inode;
-   struct posix_acl *acl;
-   int type, error = 0;
-
-   if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0)
-   type = ACL_TYPE_ACCESS;
-   else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0)
-   type = ACL_TYPE_DEFAULT;
-   else
-   return -EOPNOTSUPP;
-
-   acl = nfs3_proc_getacl(inode, type);
-   if (IS_ERR(acl))
-   return PTR_ERR(acl);
-   else if (acl) {
-   if (type == ACL_TYPE_ACCESS && acl->a_count == 0)
-   error = -ENODATA;
-   else
-   error = posix_acl_to_xattr(&init_user_ns, acl, buffer, 
size);
-   posix_acl_release(acl);
-   } else
-   error = -ENODATA;
-
-   return error;
-}
-
-int nfs3_setxattr(struct dentry *dentry, const char *name,
-const void *value, size_t size, int flags)
-{
-   struct inode *inode = dentry->d_inode;
-   struct posix_acl *acl;
-   int type, error;
-
-   if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0)
-   type = ACL_TYPE_ACCESS;
-   else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0)
-   type = ACL_TYPE_DEFAULT;
-   else
-   return -EOPNOTSUPP;
-
-   acl = posix_acl_from_xattr(&init_user_ns, value, size);
-   if (IS_ERR(acl))
-   return PTR_ERR(acl);
-   error = nfs3_proc_setacl(inode, type, acl);
-   posix_acl_release(acl);
-
-   return error;
-}
-
-int nfs3_removexattr(struct dentry *dentry, const char *name)
-{
-   struct inode *inode = dentry->d_inode;
-   int type;
-
-   if (strcmp(name, POSIX_ACL_XATTR_ACCESS) == 0)
-   type = ACL_TYPE_ACCESS;
-   else if (strcmp(name, POSIX_ACL_XATTR_DEFAULT) == 0)
-   type = ACL_TYPE_DEFAULT;
-   else
-   return -EOPNOTSUPP;
-
-   return nfs3_proc_setacl(inode, type, NULL);
-}
-
-static void __nfs3_forget_cached_acls(struct nfs_inode *nfsi)
-{
-   if (!IS_ERR(nfsi->acl_access)) {
-   posix_acl_release(nfsi->acl_access);
-   nfsi->acl_access = ERR_PTR(-EAGAIN);
-   }
-   if (!IS_ERR(nfsi->acl_default)) {
-   posix_acl_release(nfsi->acl_default);
-   nfsi->acl_de

[PATCH 17/21] gfs2: use generic posix ACL infrastructure

2013-12-20 Thread Christoph Hellwig
This contains some major refactoring for the create path so that
inodes are created with the right mode to start with instead of
fixing it up later.

Signed-off-by: Christoph Hellwig 
---
 fs/gfs2/acl.c   |  234 +++
 fs/gfs2/acl.h   |4 +-
 fs/gfs2/inode.c |   34 ++--
 fs/gfs2/xattr.c |4 +-
 4 files changed, 62 insertions(+), 214 deletions(-)

diff --git a/fs/gfs2/acl.c b/fs/gfs2/acl.c
index e82e4ac..ba94566 100644
--- a/fs/gfs2/acl.c
+++ b/fs/gfs2/acl.c
@@ -49,10 +49,6 @@ struct posix_acl *gfs2_get_acl(struct inode *inode, int type)
if (!ip->i_eattr)
return NULL;
 
-   acl = get_cached_acl(&ip->i_inode, type);
-   if (acl != ACL_NOT_CACHED)
-   return acl;
-
name = gfs2_acl_name(type);
if (name == NULL)
return ERR_PTR(-EINVAL);
@@ -80,7 +76,7 @@ static int gfs2_set_mode(struct inode *inode, umode_t mode)
return error;
 }
 
-static int gfs2_acl_set(struct inode *inode, int type, struct posix_acl *acl)
+int gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
 {
int error;
int len;
@@ -88,219 +84,49 @@ static int gfs2_acl_set(struct inode *inode, int type, 
struct posix_acl *acl)
const char *name = gfs2_acl_name(type);
 
BUG_ON(name == NULL);
-   len = posix_acl_to_xattr(&init_user_ns, acl, NULL, 0);
-   if (len == 0)
-   return 0;
-   data = kmalloc(len, GFP_NOFS);
-   if (data == NULL)
-   return -ENOMEM;
-   error = posix_acl_to_xattr(&init_user_ns, acl, data, len);
-   if (error < 0)
-   goto out;
-   error = __gfs2_xattr_set(inode, name, data, len, 0, GFS2_EATYPE_SYS);
-   if (!error)
-   set_cached_acl(inode, type, acl);
-out:
-   kfree(data);
-   return error;
-}
-
-int gfs2_acl_create(struct gfs2_inode *dip, struct inode *inode)
-{
-   struct gfs2_sbd *sdp = GFS2_SB(&dip->i_inode);
-   struct posix_acl *acl;
-   umode_t mode = inode->i_mode;
-   int error = 0;
-
-   if (!sdp->sd_args.ar_posix_acl)
-   return 0;
-   if (S_ISLNK(inode->i_mode))
-   return 0;
-
-   acl = gfs2_get_acl(&dip->i_inode, ACL_TYPE_DEFAULT);
-   if (IS_ERR(acl))
-   return PTR_ERR(acl);
-   if (!acl) {
-   mode &= ~current_umask();
-   return gfs2_set_mode(inode, mode);
-   }
-
-   if (S_ISDIR(inode->i_mode)) {
-   error = gfs2_acl_set(inode, ACL_TYPE_DEFAULT, acl);
-   if (error)
-   goto out;
-   }
-
-   error = __posix_acl_create(&acl, GFP_NOFS, &mode);
-   if (error < 0)
-   return error;
 
-   if (error == 0)
-   goto munge;
-
-   error = gfs2_acl_set(inode, ACL_TYPE_ACCESS, acl);
-   if (error)
-   goto out;
-munge:
-   error = gfs2_set_mode(inode, mode);
-out:
-   posix_acl_release(acl);
-   return error;
-}
-
-int gfs2_acl_chmod(struct gfs2_inode *ip, struct iattr *attr)
-{
-   struct inode *inode = &ip->i_inode;
-   struct posix_acl *acl;
-   char *data;
-   unsigned int len;
-   int error;
-
-   acl = gfs2_get_acl(&ip->i_inode, ACL_TYPE_ACCESS);
-   if (IS_ERR(acl))
-   return PTR_ERR(acl);
-   if (!acl)
-   return gfs2_setattr_simple(inode, attr);
-
-   error = __posix_acl_chmod(&acl, GFP_NOFS, attr->ia_mode);
-   if (error)
-   return error;
-
-   len = posix_acl_to_xattr(&init_user_ns, acl, NULL, 0);
-   data = kmalloc(len, GFP_NOFS);
-   error = -ENOMEM;
-   if (data == NULL)
-   goto out;
-   posix_acl_to_xattr(&init_user_ns, acl, data, len);
-   error = gfs2_xattr_acl_chmod(ip, attr, data);
-   kfree(data);
-   set_cached_acl(&ip->i_inode, ACL_TYPE_ACCESS, acl);
-
-out:
-   posix_acl_release(acl);
-   return error;
-}
-
-static int gfs2_acl_type(const char *name)
-{
-   if (strcmp(name, GFS2_POSIX_ACL_ACCESS) == 0)
-   return ACL_TYPE_ACCESS;
-   if (strcmp(name, GFS2_POSIX_ACL_DEFAULT) == 0)
-   return ACL_TYPE_DEFAULT;
-   return -EINVAL;
-}
-
-static int gfs2_xattr_system_get(struct dentry *dentry, const char *name,
-void *buffer, size_t size, int xtype)
-{
-   struct inode *inode = dentry->d_inode;
-   struct gfs2_sbd *sdp = GFS2_SB(inode);
-   struct posix_acl *acl;
-   int type;
-   int error;
-
-   if (!sdp->sd_args.ar_posix_acl)
-   return -EOPNOTSUPP;
-
-   type = gfs2_acl_type(name);
-   if (type < 0)
-   return type;
-
-   acl = gfs2_get_acl(inode, type);
-   if (IS_ERR(acl))
-   return PTR_ERR(acl);
-   if (acl == NULL)
-   return -ENODATA;
-
-   error = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
-   posix_

[PATCH 19/21] fs: remove generic_acl

2013-12-20 Thread Christoph Hellwig
And instead convert tmpfs to use the new generic ACL code, with two stub
methods provided for in-memory filesystems.

Signed-off-by: Christoph Hellwig 
---
 fs/Kconfig  |6 +-
 fs/Makefile |1 -
 fs/generic_acl.c|  184 ---
 fs/posix_acl.c  |   36 +
 include/linux/generic_acl.h |   14 
 include/linux/posix_acl.h   |9 +++
 mm/shmem.c  |   57 ++
 7 files changed, 69 insertions(+), 238 deletions(-)
 delete mode 100644 fs/generic_acl.c
 delete mode 100644 include/linux/generic_acl.h

diff --git a/fs/Kconfig b/fs/Kconfig
index c229f82..7385e54 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -68,10 +68,6 @@ source "fs/quota/Kconfig"
 source "fs/autofs4/Kconfig"
 source "fs/fuse/Kconfig"
 
-config GENERIC_ACL
-   bool
-   select FS_POSIX_ACL
-
 menu "Caches"
 
 source "fs/fscache/Kconfig"
@@ -119,7 +115,7 @@ config TMPFS_POSIX_ACL
bool "Tmpfs POSIX Access Control Lists"
depends on TMPFS
select TMPFS_XATTR
-   select GENERIC_ACL
+   select FS_POSIX_ACL
help
  POSIX Access Control Lists (ACLs) support additional access rights
  for users and groups beyond the standard owner/group/world scheme,
diff --git a/fs/Makefile b/fs/Makefile
index f2c1843..5bebad4 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -44,7 +44,6 @@ obj-$(CONFIG_BINFMT_FLAT) += binfmt_flat.o
 obj-$(CONFIG_FS_MBCACHE)   += mbcache.o
 obj-$(CONFIG_FS_POSIX_ACL) += posix_acl.o
 obj-$(CONFIG_NFS_COMMON)   += nfs_common/
-obj-$(CONFIG_GENERIC_ACL)  += generic_acl.o
 obj-$(CONFIG_COREDUMP) += coredump.o
 obj-$(CONFIG_SYSCTL)   += drop_caches.o
 
diff --git a/fs/generic_acl.c b/fs/generic_acl.c
deleted file mode 100644
index 4357f39..000
--- a/fs/generic_acl.c
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * (C) 2005 Andreas Gruenbacher 
- *
- * This file is released under the GPL.
- *
- * Generic ACL support for in-memory filesystems.
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-
-static size_t
-generic_acl_list(struct dentry *dentry, char *list, size_t list_size,
-   const char *name, size_t name_len, int type)
-{
-   struct posix_acl *acl;
-   const char *xname;
-   size_t size;
-
-   acl = get_cached_acl(dentry->d_inode, type);
-   if (!acl)
-   return 0;
-   posix_acl_release(acl);
-
-   switch (type) {
-   case ACL_TYPE_ACCESS:
-   xname = POSIX_ACL_XATTR_ACCESS;
-   break;
-   case ACL_TYPE_DEFAULT:
-   xname = POSIX_ACL_XATTR_DEFAULT;
-   break;
-   default:
-   return 0;
-   }
-   size = strlen(xname) + 1;
-   if (list && size <= list_size)
-   memcpy(list, xname, size);
-   return size;
-}
-
-static int
-generic_acl_get(struct dentry *dentry, const char *name, void *buffer,
-size_t size, int type)
-{
-   struct posix_acl *acl;
-   int error;
-
-   if (strcmp(name, "") != 0)
-   return -EINVAL;
-
-   acl = get_cached_acl(dentry->d_inode, type);
-   if (!acl)
-   return -ENODATA;
-   error = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
-   posix_acl_release(acl);
-
-   return error;
-}
-
-static int
-generic_acl_set(struct dentry *dentry, const char *name, const void *value,
-size_t size, int flags, int type)
-{
-   struct inode *inode = dentry->d_inode;
-   struct posix_acl *acl = NULL;
-   int error;
-
-   if (strcmp(name, "") != 0)
-   return -EINVAL;
-   if (S_ISLNK(inode->i_mode))
-   return -EOPNOTSUPP;
-   if (!inode_owner_or_capable(inode))
-   return -EPERM;
-   if (value) {
-   acl = posix_acl_from_xattr(&init_user_ns, value, size);
-   if (IS_ERR(acl))
-   return PTR_ERR(acl);
-   }
-   if (acl) {
-   error = posix_acl_valid(acl);
-   if (error)
-   goto failed;
-   switch (type) {
-   case ACL_TYPE_ACCESS:
-   error = posix_acl_equiv_mode(acl, &inode->i_mode);
-   if (error < 0)
-   goto failed;
-   inode->i_ctime = CURRENT_TIME;
-   if (error == 0) {
-   posix_acl_release(acl);
-   acl = NULL;
-   }
-   break;
-   case ACL_TYPE_DEFAULT:
-   if (!S_ISDIR(inode->i_mode)) {
-   error = -EINVAL;
-   goto failed;
-   }
-   break;
-   }
-   }
-   set_cached_acl(inode, type, acl);
-   error = 0;
-fai

[PATCH 0/0] Consolidate Posix ACL implementation V3

2013-12-20 Thread Christoph Hellwig
This series consolidates the various cut'n'pasted Posix ACL implementations
into a single common one based on the ->get_acl method Linus added a while
ago and a new ->set_acl counterpart.

This remove ~1800 lines of code and provides a single place to implement
various nasty little gems of the semantics.

Unfortunately the 9p code is still left out - it implements the ACLs
in two very weird ways, one using the common code but on the client only,
and one pasing things straight through to the server.  We could easily
convert it to the new code on the write side if ->set_acl took a dentry,
but there's no cance to do that on the ->get_acl side.  Ideas how to
handle it welcome.

After that we'd be ready to never go into the fs for the ACL attributes
and branch straight to the ACL code below the syscall, repairing the
old API braindamage of overloading ACLs onto the xattrs.


Changes from V2:
 - remove redundant S_ISLNK checks
 - fix the get_acl return value
 - remove spurious symlink get_acl instance in gfs2
 - fix default ACL inheritance on NFS
 - use get_acl and set_acl from the NFS server
 - remove some incorrectly copy&pasted code in hfsplus

Changes from V1:
 - check for symlinks in the ACL code and remove checks in the lower
   level functions.
 - remove get_acl instances for symlinks in a few filesystems
 - pass a umode_t mode argument to posix_acl_chmod to accomodate f2fs
 - various cosemtic bits from the reviews.

Note that I still haven't heard from ocfs2 folks, so the patch is left
unchanged.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: btrfs on bcache

2013-12-20 Thread Fábio Pfeifer
Hello,

I put the "WARN_ON(1);" after the printk lines (incomplete page read
and incomplete page write) in extent_io.c.

here some call traces:

[   19.509497] incomplete page read in btrfs with offset 2560 and length 1536
[   19.509500] [ cut here ]
[   19.509528] WARNING: CPU: 2 PID: 220 at fs/btrfs/extent_io.c:2441
end_bio_extent_readpage+0x788/0xc20 [btrfs]()
[   19.509530] Modules linked in: cdc_acm fuse iTCO_wdt
iTCO_vendor_support snd_hda_codec_analog coretemp kvm_intel kvm raid1
ext4 crc16 md_mod mbcache jbd2 microcode nvidia(PO) psmouse pcspkr
evdev serio_raw i2c_i801 lpc_ich i2c_core snd_hda_intel sky2 skge
i82975x_edac button asus_atk0110 snd_hda_codec snd_hwdep shpchp
snd_pcm snd_page_alloc snd_timer acpi_cpufreq snd edac_core soundcore
processor vboxdrv(O) sr_mod cdrom ata_generic pata_acpi hid_generic
usbhid hid usb_storage sd_mod pata_marvell firewire_ohci uhci_hcd ahci
ehci_pci firewire_core ata_piix libahci crc_itu_t ehci_hcd libata
scsi_mod usbcore usb_common btrfs crc32c libcrc32c xor raid6_pq bcache
[   19.509578] CPU: 2 PID: 220 Comm: btrfs-endio-met Tainted: P
W  O 3.12.5-1-ARCH #1
[   19.509580] Hardware name: System manufacturer System Product
Name/P5WDG2 WS Pro, BIOS 090503/06/2008
[   19.509581]  0009 880231a63cb0 814ee37b

[   19.509585]  880231a63ce8 81062bcd ea00085eaec0

[   19.509587]  8802320cc9c0  880233b0e000
880231a63cf8
[   19.509590] Call Trace:
[   19.509596]  [] dump_stack+0x54/0x8d
[   19.509601]  [] warn_slowpath_common+0x7d/0xa0
[   19.509603]  [] warn_slowpath_null+0x1a/0x20
[   19.509614]  [] end_bio_extent_readpage+0x788/0xc20 [btrfs]
[   19.509617]  [] ? lock_timer_base.isra.35+0x2b/0x50
[   19.509619]  [] ? detach_if_pending+0x120/0x120
[   19.509623]  [] bio_endio+0x1d/0x30
[   19.509632]  [] end_workqueue_fn+0x37/0x40 [btrfs]
[   19.509642]  [] worker_loop+0x14e/0x560 [btrfs]
[   19.509646]  [] ? default_wake_function+0x12/0x20
[   19.509656]  [] ? btrfs_queue_worker+0x330/0x330 [btrfs]
[   19.509672]  [] kthread+0xc0/0xd0
[   19.509677]  [] ? kthread_create_on_node+0x120/0x120
[   19.509680]  [] ret_from_fork+0x7c/0xb0
[   19.509683]  [] ? kthread_create_on_node+0x120/0x120
[   19.509687] ---[ end trace bbc8d0d088375446 ]---
[   25.592100] incomplete page read in btrfs with offset 2560 and length 1536
[   25.592105] [ cut here ]
[   25.592141] WARNING: CPU: 0 PID: 442 at fs/btrfs/extent_io.c:2441
end_bio_extent_readpage+0x788/0xc20 [btrfs]()
[   25.592143] Modules linked in: cdc_acm fuse iTCO_wdt
iTCO_vendor_support snd_hda_codec_analog coretemp kvm_intel kvm raid1
ext4 crc16 md_mod mbcache jbd2 microcode nvidia(PO) psmouse pcspkr
evdev serio_raw i2c_i801 lpc_ich i2c_core snd_hda_intel sky2 skge
i82975x_edac button asus_atk0110 snd_hda_codec snd_hwdep shpchp
snd_pcm snd_page_alloc snd_timer acpi_cpufreq snd edac_core soundcore
processor vboxdrv(O) sr_mod cdrom ata_generic pata_acpi hid_generic
usbhid hid usb_storage sd_mod pata_marvell firewire_ohci uhci_hcd ahci
ehci_pci firewire_core ata_piix libahci crc_itu_t ehci_hcd libata
scsi_mod usbcore usb_common btrfs crc32c libcrc32c xor raid6_pq bcache
[   25.592205] CPU: 0 PID: 442 Comm: btrfs-endio-met Tainted: P
W  O 3.12.5-1-ARCH #1
[   25.592208] Hardware name: System manufacturer System Product
Name/P5WDG2 WS Pro, BIOS 090503/06/2008
[   25.592211]  0009 880229773cb0 814ee37b

[   25.592216]  880229773ce8 81062bcd ea0002a20a80

[   25.592220]  88022d3ab180  88022d326000
880229773cf8
[   25.592225] Call Trace:
[   25.592234]  [] dump_stack+0x54/0x8d
[   25.592240]  [] warn_slowpath_common+0x7d/0xa0
[   25.592245]  [] warn_slowpath_null+0x1a/0x20
[   25.592262]  [] end_bio_extent_readpage+0x788/0xc20 [btrfs]
[   25.592267]  [] ? try_to_del_timer_sync+0x4f/0x70
[   25.592271]  [] ? del_timer_sync+0x52/0x60
[   25.592275]  [] ? detach_if_pending+0x120/0x120
[   25.592280]  [] bio_endio+0x1d/0x30
[   25.592296]  [] end_workqueue_fn+0x37/0x40 [btrfs]
[   25.592312]  [] worker_loop+0x14e/0x560 [btrfs]
[   25.592318]  [] ? default_wake_function+0x12/0x20
[   25.592335]  [] ? btrfs_queue_worker+0x330/0x330 [btrfs]
[   25.592350]  [] kthread+0xc0/0xd0
[   25.592353]  [] ? kthread_create_on_node+0x120/0x120
[   25.592356]  [] ret_from_fork+0x7c/0xb0
[   25.592359]  [] ? kthread_create_on_node+0x120/0x120
[   25.592360] ---[ end trace bbc8d0d088375447 ]---

thanks,

Fabio Pfeifer

2013/12/19 Chris Mason :
> On Wed, 2013-12-18 at 18:17 +0100, eb wrote:
>> I've recently setup a system (Kernel 3.12.5-1-ARCH) which is layered as 
>> follows:
>>
>> /dev/sdb3 - cache0 (80 GB Intel SSD)
>> /dev/sdc1 - backing device (2 TB WD HDD)
>>
>> sdb3+sdc1 => /dev/bcache0
>>
>> On /dev/bcache0, there's a btrfs filesystem with 2 subvolumes, mounted
>> as / and /home. What's been bother

Re: btrfs on bcache

2013-12-20 Thread eb
On Thu, Dec 19, 2013 at 8:59 PM, Chris Mason  wrote:
> On Wed, 2013-12-18 at 18:17 +0100, eb wrote:
> Btrfs shouldn't be setting the offset on the bios.  Are you able to add
> a WARN_ON to the message that prints this so we can see the stack trace?

If you send me a patch - my experience on hacking on the kernel is
exactly 0 - I'll try to see if I can compile a custom kernel and get
it running.

> Could you please cc the bcache and btrfs list together?

Done.

I did some more testing - I copied an image of a 128GB drive over the
network (via netcat) onto the bcache/btrfs system and verified the
results twice using sha1sum. They're both identical on the source
system (which is *not* using bcache) and bcache/btrfs setup. I've
gotten a lot of the incomplete write errors and a few csum erros in
dmesg, but apparently they haven't done any harm?

Not sure how remarkable this is, as these kinds of things are supposed
to bypass the cache anyway, but I assume they still have to go through
the subsystem.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html