[GFS2] Update copyright, tidy up incore.h
[safe/jmp/linux-2.6] / fs / gfs2 / quota.c
index 942c4c8..be87983 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * Copyright (C) Sistina Software, Inc.  1997-2003 All rights reserved.
- * Copyright (C) 2004-2005 Red Hat, Inc.  All rights reserved.
+ * Copyright (C) 2004-2006 Red Hat, Inc.  All rights reserved.
  *
  * This copyrighted material is made available to anyone wishing to use,
  * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU General Public License v.2.
+ * of the GNU General Public License version 2.
  */
 
 /*
 #include <linux/spinlock.h>
 #include <linux/completion.h>
 #include <linux/buffer_head.h>
-#include <linux/tty.h>
 #include <linux/sort.h>
 #include <linux/fs.h>
 #include <linux/gfs2_ondisk.h>
-#include <asm/semaphore.h>
 
 #include "gfs2.h"
 #include "lm_interface.h"
@@ -54,7 +52,6 @@
 #include "glock.h"
 #include "glops.h"
 #include "log.h"
-#include "lvb.h"
 #include "meta_io.h"
 #include "quota.h"
 #include "rgrp.h"
@@ -249,12 +246,13 @@ static void slot_put(struct gfs2_quota_data *qd)
 static int bh_get(struct gfs2_quota_data *qd)
 {
        struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
-       struct gfs2_inode *ip = sdp->sd_qc_inode->u.generic_ip;
+       struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode);
        unsigned int block, offset;
        uint64_t dblock;
        int new = 0;
        struct buffer_head *bh;
        int error;
+       int boundary;
 
        mutex_lock(&sdp->sd_quota_mutex);
 
@@ -266,7 +264,7 @@ static int bh_get(struct gfs2_quota_data *qd)
        block = qd->qd_slot / sdp->sd_qc_per_block;
        offset = qd->qd_slot % sdp->sd_qc_per_block;;
 
-       error = gfs2_block_map(ip, block, &new, &dblock, NULL);
+       error = gfs2_block_map(&ip->i_inode, block, &new, &dblock, &boundary);
        if (error)
                goto fail;
        error = gfs2_meta_read(ip->i_gl, dblock, DIO_START | DIO_WAIT, &bh);
@@ -444,7 +442,7 @@ static void qdsb_put(struct gfs2_quota_data *qd)
 
 int gfs2_quota_hold(struct gfs2_inode *ip, uint32_t uid, uint32_t gid)
 {
-       struct gfs2_sbd *sdp = ip->i_sbd;
+       struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
        struct gfs2_alloc *al = &ip->i_alloc;
        struct gfs2_quota_data **qd = al->al_qd;
        int error;
@@ -493,7 +491,7 @@ int gfs2_quota_hold(struct gfs2_inode *ip, uint32_t uid, uint32_t gid)
 
 void gfs2_quota_unhold(struct gfs2_inode *ip)
 {
-       struct gfs2_sbd *sdp = ip->i_sbd;
+       struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
        struct gfs2_alloc *al = &ip->i_alloc;
        unsigned int x;
 
@@ -531,7 +529,7 @@ static int sort_qd(const void *a, const void *b)
 static void do_qc(struct gfs2_quota_data *qd, int64_t change)
 {
        struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
-       struct gfs2_inode *ip = sdp->sd_qc_inode->u.generic_ip;
+       struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode);
        struct gfs2_quota_change *qc = qd->qd_bh_qc;
        int64_t x;
 
@@ -578,7 +576,7 @@ static void do_qc(struct gfs2_quota_data *qd, int64_t change)
 static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc,
                             int64_t change, struct gfs2_quota_data *qd)
 {
-       struct inode *inode = ip->i_vnode;
+       struct inode *inode = &ip->i_inode;
        struct address_space *mapping = inode->i_mapping;
        unsigned long index = loc >> PAGE_CACHE_SHIFT;
        unsigned offset = loc & (PAGE_CACHE_SHIFT - 1);
@@ -587,7 +585,7 @@ static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc,
        struct page *page;
        void *kaddr;
        __be64 *ptr;
-       u64 value;
+       s64 value;
        int err = -EIO;
 
        page = grab_cache_page(mapping, index);
@@ -628,7 +626,8 @@ static int gfs2_adjust_quota(struct gfs2_inode *ip, loff_t loc,
 
        kaddr = kmap_atomic(page, KM_USER0);
        ptr = (__be64 *)(kaddr + offset);
-       value = *ptr = cpu_to_be64(be64_to_cpu(*ptr) + change);
+       value = (s64)be64_to_cpu(*ptr) + change;
+       *ptr = cpu_to_be64(value);
        flush_dcache_page(page);
        kunmap_atomic(kaddr, KM_USER0);
        err = 0;
@@ -647,9 +646,8 @@ unlock:
 static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda)
 {
        struct gfs2_sbd *sdp = (*qda)->qd_gl->gl_sbd;
-       struct gfs2_inode *ip = sdp->sd_quota_inode->u.generic_ip;
+       struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode);
        unsigned int data_blocks, ind_blocks;
-       struct file_ra_state ra_state;
        struct gfs2_holder *ghs, i_gh;
        unsigned int qx, x;
        struct gfs2_quota_data *qd;
@@ -716,7 +714,6 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda)
                        goto out_gunlock;
        }
 
-       file_ra_state_init(&ra_state, ip->i_vnode->i_mapping);
        for (x = 0; x < num_qd; x++) {
                qd = qda[x];
                offset = qd2offset(qd);
@@ -758,12 +755,13 @@ static int do_glock(struct gfs2_quota_data *qd, int force_refresh,
                    struct gfs2_holder *q_gh)
 {
        struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
-       struct gfs2_inode *ip = sdp->sd_quota_inode->u.generic_ip;
+       struct gfs2_inode *ip = GFS2_I(sdp->sd_quota_inode);
        struct gfs2_holder i_gh;
        struct gfs2_quota q;
        char buf[sizeof(struct gfs2_quota)];
        struct file_ra_state ra_state;
        int error;
+       struct gfs2_quota_lvb *qlvb;
 
        file_ra_state_init(&ra_state, sdp->sd_quota_inode->i_mapping);
  restart:
@@ -771,9 +769,9 @@ static int do_glock(struct gfs2_quota_data *qd, int force_refresh,
        if (error)
                return error;
 
-       gfs2_quota_lvb_in(&qd->qd_qb, qd->qd_gl->gl_lvb);
+       qd->qd_qb = *(struct gfs2_quota_lvb *)qd->qd_gl->gl_lvb;
 
-       if (force_refresh || qd->qd_qb.qb_magic != GFS2_MAGIC) {
+       if (force_refresh || qd->qd_qb.qb_magic != cpu_to_be32(GFS2_MAGIC)) {
                loff_t pos;
                gfs2_glock_dq_uninit(q_gh);
                error = gfs2_glock_nq_init(qd->qd_gl,
@@ -782,32 +780,28 @@ static int do_glock(struct gfs2_quota_data *qd, int force_refresh,
                if (error)
                        return error;
 
-               error = gfs2_glock_nq_init(ip->i_gl,
-                                         LM_ST_SHARED, 0,
-                                         &i_gh);
+               error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &i_gh);
                if (error)
                        goto fail;
 
                memset(buf, 0, sizeof(struct gfs2_quota));
                pos = qd2offset(qd);
-               error = gfs2_internal_read(ip,
-                                           &ra_state, buf,
-                                           &pos,
-                                           sizeof(struct gfs2_quota));
+               error = gfs2_internal_read(ip, &ra_state, buf,
+                                          &pos, sizeof(struct gfs2_quota));
                if (error < 0)
                        goto fail_gunlock;
 
                gfs2_glock_dq_uninit(&i_gh);
 
+               
                gfs2_quota_in(&q, buf);
-
-               memset(&qd->qd_qb, 0, sizeof(struct gfs2_quota_lvb));
-               qd->qd_qb.qb_magic = GFS2_MAGIC;
-               qd->qd_qb.qb_limit = q.qu_limit;
-               qd->qd_qb.qb_warn = q.qu_warn;
-               qd->qd_qb.qb_value = q.qu_value;
-
-               gfs2_quota_lvb_out(&qd->qd_qb, qd->qd_gl->gl_lvb);
+               qlvb = (struct gfs2_quota_lvb *)qd->qd_gl->gl_lvb;
+               qlvb->qb_magic = cpu_to_be32(GFS2_MAGIC);
+               qlvb->__pad = 0;
+               qlvb->qb_limit = cpu_to_be64(q.qu_limit);
+               qlvb->qb_warn = cpu_to_be64(q.qu_warn);
+               qlvb->qb_value = cpu_to_be64(q.qu_value);
+               qd->qd_qb = *qlvb;
 
                if (gfs2_glock_is_blocking(qd->qd_gl)) {
                        gfs2_glock_dq_uninit(q_gh);
@@ -829,7 +823,7 @@ static int do_glock(struct gfs2_quota_data *qd, int force_refresh,
 
 int gfs2_quota_lock(struct gfs2_inode *ip, uint32_t uid, uint32_t gid)
 {
-       struct gfs2_sbd *sdp = ip->i_sbd;
+       struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
        struct gfs2_alloc *al = &ip->i_alloc;
        unsigned int x;
        int error = 0;
@@ -882,13 +876,14 @@ static int need_sync(struct gfs2_quota_data *qd)
 
        if (value < 0)
                do_sync = 0;
-       else if (qd->qd_qb.qb_value >= (int64_t)qd->qd_qb.qb_limit)
+       else if ((s64)be64_to_cpu(qd->qd_qb.qb_value) >=
+                (s64)be64_to_cpu(qd->qd_qb.qb_limit))
                do_sync = 0;
        else {
                value *= gfs2_jindex_size(sdp) * num;
                do_div(value, den);
-               value += qd->qd_qb.qb_value;
-               if (value < (int64_t)qd->qd_qb.qb_limit)
+               value += (s64)be64_to_cpu(qd->qd_qb.qb_value);
+               if (value < (int64_t)be64_to_cpu(qd->qd_qb.qb_limit))
                        do_sync = 0;
        }
 
@@ -933,32 +928,18 @@ void gfs2_quota_unlock(struct gfs2_inode *ip)
 static int print_message(struct gfs2_quota_data *qd, char *type)
 {
        struct gfs2_sbd *sdp = qd->qd_gl->gl_sbd;
-       char *line;
-       int len;
-
-       line = kmalloc(MAX_LINE, GFP_KERNEL);
-       if (!line)
-               return -ENOMEM;
-
-       len = snprintf(line, MAX_LINE-1,
-                      "GFS2: fsid=%s: quota %s for %s %u\r\n",
-                      sdp->sd_fsname, type,
-                      (test_bit(QDF_USER, &qd->qd_flags)) ? "user" : "group",
-                      qd->qd_id);
-       line[MAX_LINE-1] = 0;
-
-       if (current->signal) { /* Is this test still required? */
-               tty_write_message(current->signal->tty, line);
-       }
 
-       kfree(line);
+       printk(KERN_INFO "GFS2: fsid=%s: quota %s for %s %u\r\n",
+              sdp->sd_fsname, type,
+              (test_bit(QDF_USER, &qd->qd_flags)) ? "user" : "group",
+              qd->qd_id);
 
        return 0;
 }
 
 int gfs2_quota_check(struct gfs2_inode *ip, uint32_t uid, uint32_t gid)
 {
-       struct gfs2_sbd *sdp = ip->i_sbd;
+       struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
        struct gfs2_alloc *al = &ip->i_alloc;
        struct gfs2_quota_data *qd;
        int64_t value;
@@ -978,17 +959,17 @@ int gfs2_quota_check(struct gfs2_inode *ip, uint32_t uid, uint32_t gid)
                      (qd->qd_id == gid && !test_bit(QDF_USER, &qd->qd_flags))))
                        continue;
 
-               value = qd->qd_qb.qb_value;
+               value = (s64)be64_to_cpu(qd->qd_qb.qb_value);
                spin_lock(&sdp->sd_quota_spin);
                value += qd->qd_change;
                spin_unlock(&sdp->sd_quota_spin);
 
-               if (qd->qd_qb.qb_limit && (int64_t)qd->qd_qb.qb_limit < value) {
+               if (be64_to_cpu(qd->qd_qb.qb_limit) && (int64_t)be64_to_cpu(qd->qd_qb.qb_limit) < value) {
                        print_message(qd, "exceeded");
                        error = -EDQUOT;
                        break;
-               } else if (qd->qd_qb.qb_warn &&
-                          (int64_t)qd->qd_qb.qb_warn < value &&
+               } else if (be64_to_cpu(qd->qd_qb.qb_warn) &&
+                          (int64_t)be64_to_cpu(qd->qd_qb.qb_warn) < value &&
                           time_after_eq(jiffies, qd->qd_last_warn +
                                         gfs2_tune_get(sdp,
                                                gt_quota_warn_period) * HZ)) {
@@ -1008,7 +989,7 @@ void gfs2_quota_change(struct gfs2_inode *ip, int64_t change,
        unsigned int x;
        unsigned int found = 0;
 
-       if (gfs2_assert_warn(ip->i_sbd, change))
+       if (gfs2_assert_warn(GFS2_SB(&ip->i_inode), change))
                return;
        if (ip->i_di.di_flags & GFS2_DIF_SYSTEM)
                return;
@@ -1107,9 +1088,9 @@ int gfs2_quota_read(struct gfs2_sbd *sdp, int user, uint32_t id,
                goto out;
 
        memset(q, 0, sizeof(struct gfs2_quota));
-       q->qu_limit = qd->qd_qb.qb_limit;
-       q->qu_warn = qd->qd_qb.qb_warn;
-       q->qu_value = qd->qd_qb.qb_value;
+       q->qu_limit = be64_to_cpu(qd->qd_qb.qb_limit);
+       q->qu_warn = be64_to_cpu(qd->qd_qb.qb_warn);
+       q->qu_value = be64_to_cpu(qd->qd_qb.qb_value);
 
        spin_lock(&sdp->sd_quota_spin);
        q->qu_value += qd->qd_change;
@@ -1126,7 +1107,7 @@ int gfs2_quota_read(struct gfs2_sbd *sdp, int user, uint32_t id,
 
 int gfs2_quota_init(struct gfs2_sbd *sdp)
 {
-       struct gfs2_inode *ip = sdp->sd_qc_inode->u.generic_ip;
+       struct gfs2_inode *ip = GFS2_I(sdp->sd_qc_inode);
        unsigned int blocks = ip->i_di.di_size >> sdp->sd_sb.sb_bsize_shift;
        unsigned int x, slot = 0;
        unsigned int found = 0;
@@ -1162,7 +1143,7 @@ int gfs2_quota_init(struct gfs2_sbd *sdp)
 
                if (!extlen) {
                        int new = 0;
-                       error = gfs2_block_map(ip, x, &new, &dblock, &extlen);
+                       error = gfs2_extent_map(&ip->i_inode, x, &new, &dblock, &extlen);
                        if (error)
                                goto fail;
                }