libfs: allow error return from simple attributes

Sometimes simple attributes might need to return an error, e.g. for
acquiring a mutex interruptibly.  In fact we have that situation in
spufs already which is the original user of the simple attributes.  This
patch merged the temporarily forked attributes in spufs back into the
main ones and allows to return errors.

[akpm@linux-foundation.org: build fix]
Signed-off-by: Christoph Hellwig <hch@lst.de>
Cc: <stefano.brivio@polimi.it>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Greg KH <greg@kroah.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Christoph Hellwig
2008-02-08 04:20:26 -08:00
committed by Linus Torvalds
parent efae09f3e9
commit 8b88b0998e
7 changed files with 69 additions and 47 deletions

View File

@@ -1186,38 +1186,38 @@ static struct notifier_block kvm_cpu_notifier = {
.priority = 20, /* must be > scheduler priority */
};
static u64 vm_stat_get(void *_offset)
static int vm_stat_get(void *_offset, u64 *val)
{
unsigned offset = (long)_offset;
u64 total = 0;
struct kvm *kvm;
*val = 0;
spin_lock(&kvm_lock);
list_for_each_entry(kvm, &vm_list, vm_list)
total += *(u32 *)((void *)kvm + offset);
*val += *(u32 *)((void *)kvm + offset);
spin_unlock(&kvm_lock);
return total;
return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(vm_stat_fops, vm_stat_get, NULL, "%llu\n");
static u64 vcpu_stat_get(void *_offset)
static int vcpu_stat_get(void *_offset, u64 *val)
{
unsigned offset = (long)_offset;
u64 total = 0;
struct kvm *kvm;
struct kvm_vcpu *vcpu;
int i;
*val = 0;
spin_lock(&kvm_lock);
list_for_each_entry(kvm, &vm_list, vm_list)
for (i = 0; i < KVM_MAX_VCPUS; ++i) {
vcpu = kvm->vcpus[i];
if (vcpu)
total += *(u32 *)((void *)vcpu + offset);
*val += *(u32 *)((void *)vcpu + offset);
}
spin_unlock(&kvm_lock);
return total;
return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(vcpu_stat_fops, vcpu_stat_get, NULL, "%llu\n");