*/
#include <linux/fs.h>
+#include <linux/quotaops.h>
+#include <linux/vs_dlimit.h>
#include "jfs_incore.h"
#include "jfs_superblock.h"
#include "jfs_filsys.h"
s32 xlen;
rc = xtLookup(inode, blkno, 1, &xflag, &xaddr, &xlen, 1);
- if (rc || (xlen == 0))
+ if (rc || (xaddr == 0))
return NULL;
return read_metapage(inode, xaddr, PSIZE, 1);
s32 xlen;
rc = xtLookup(inode, blkno, 1, &xflag, &xaddr, &xlen, 1);
- if (rc || (xlen == 0))
+ if (rc || (xaddr == 0))
return NULL;
return get_metapage(inode, xaddr, PSIZE, 1);
return NULL;
}
- if (jfs_ip->next_index <= (MAX_INLINE_DIRTABLE_ENTRY + 1)) {
+ if (jfs_dirtable_inline(ip)) {
/*
* Inline directory table
*/
* It's time to move the inline table to an external
* page and begin to build the xtree
*/
+ if (DQUOT_ALLOC_BLOCK(ip, sbi->nbperpage))
+ goto clean_up;
+ if (DLIMIT_ALLOC_BLOCK(ip, sbi->nbperpage))
+ goto clean_up_quota;
if (dbAlloc(ip, 0, sbi->nbperpage, &xaddr))
- goto clean_up; /* No space */
+ goto clean_up_dlim;
/*
* Save the table, we're going to overwrite it with the
xtInitRoot(tid, ip);
/*
- * Allocate the first block & add it to the xtree
+ * Add the first block to the xtree
*/
if (xtInsert(tid, ip, 0, 0, sbi->nbperpage, &xaddr, 0)) {
/* This really shouldn't fail */
jfs_warn("add_index: xtInsert failed!");
memcpy(&jfs_ip->i_dirtable, temp_table,
sizeof (temp_table));
+ dbFree(ip, xaddr, sbi->nbperpage);
+ DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
goto clean_up;
}
ip->i_size = PSIZE;
- ip->i_blocks += LBLK2PBLK(sb, sbi->nbperpage);
if ((mp = get_index_page(ip, 0)) == 0) {
jfs_err("add_index: get_metapage failed!");
goto clean_up;
}
ip->i_size += PSIZE;
- ip->i_blocks += LBLK2PBLK(sb, sbi->nbperpage);
if ((mp = get_index_page(ip, blkno)))
memset(mp->data, 0, PSIZE); /* Just looks better */
return index;
+ clean_up_dlim:
+ DLIMIT_FREE_BLOCK(ip, sbi->nbperpage);
+ clean_up_quota:
+ DQUOT_FREE_BLOCK(ip, sbi->nbperpage);
clean_up:
jfs_ip->next_index--;
n = NDTLEAF_LEGACY(name->namlen);
data.leaf.ip = NULL; /* signifies legacy directory format */
}
- data.leaf.ino = cpu_to_le32(*fsn);
+ data.leaf.ino = *fsn;
/*
* leaf page does not have enough room for new entry:
struct dt_lock *dtlck;
struct tlock *tlck;
struct lv *lv;
+ int quota_allocation = 0;
+ int dlimit_allocation = 0;
/* get split page */
smp = split->mp;
split->pxdlist = &pxdlist;
rc = dtSplitRoot(tid, ip, split, &rmp);
- if (!rc)
+ if (rc)
+ dbFree(ip, xaddr, xlen);
+ else
DT_PUTPAGE(rmp);
DT_PUTPAGE(smp);
n = xlen + (xlen << 1);
else
n = xlen;
+
+ /* Allocate blocks to quota. */
+ if (DQUOT_ALLOC_BLOCK(ip, n)) {
+ rc = -EDQUOT;
+ goto extendOut;
+ }
+ quota_allocation += n;
+
+ if (DLIMIT_ALLOC_BLOCK(ip, n)) {
+ rc = -ENOSPC;
+ goto extendOut;
+ }
+ dlimit_allocation += n;
+
if ((rc = dbReAlloc(sbi->ipbmap, xaddr, (s64) xlen,
(s64) n, &nxaddr)))
goto extendOut;
freeKeyName:
kfree(key.name);
+ /* Rollback dlimit allocation */
+ if (rc && dlimit_allocation)
+ DLIMIT_FREE_BLOCK(ip, dlimit_allocation);
+ /* Rollback quota allocation */
+ if (rc && quota_allocation)
+ DQUOT_FREE_BLOCK(ip, quota_allocation);
+
dtSplitUp_Exit:
return rc;
static int dtSplitPage(tid_t tid, struct inode *ip, struct dtsplit * split,
struct metapage ** rmpp, dtpage_t ** rpp, pxd_t * rpxdp)
{
- struct super_block *sb = ip->i_sb;
int rc = 0;
struct metapage *smp;
dtpage_t *sp;
if (rmp == NULL)
return -EIO;
+ /* Allocate blocks to quota. */
+ if (DQUOT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
+ release_metapage(rmp);
+ return -EDQUOT;
+ }
+ /* Allocate blocks to dlimit. */
+ if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
+ DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
+ release_metapage(rmp);
+ return -ENOSPC;
+ }
+
jfs_info("dtSplitPage: ip:0x%p smp:0x%p rmp:0x%p", ip, smp, rmp);
BT_MARK_DIRTY(rmp, ip);
*rmpp = rmp;
*rpxdp = *pxd;
- ip->i_blocks += LBLK2PBLK(sb, lengthPXD(pxd));
-
return rc;
}
tpxd = (pxd_t *) & pp->slot[1];
*tpxd = *pxd;
- /* Since the directory might have an EA and/or ACL associated with it
- * we need to make sure we take that into account when setting the
- * i_nblocks
- */
- ip->i_blocks = LBLK2PBLK(ip->i_sb, xlen +
- ((JFS_IP(ip)->ea.flag & DXD_EXTENT) ?
- lengthDXD(&JFS_IP(ip)->ea) : 0) +
- ((JFS_IP(ip)->acl.flag & DXD_EXTENT) ?
- lengthDXD(&JFS_IP(ip)->acl) : 0));
-
DT_PUTPAGE(pmp);
return 0;
}
rp = rmp->data;
+ /* Allocate blocks to quota. */
+ if (DQUOT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
+ release_metapage(rmp);
+ return -EDQUOT;
+ }
+ /* Allocate blocks to dlimit. */
+ if (DLIMIT_ALLOC_BLOCK(ip, lengthPXD(pxd))) {
+ DQUOT_FREE_BLOCK(ip, lengthPXD(pxd));
+ release_metapage(rmp);
+ return -ENOSPC;
+ }
+
BT_MARK_DIRTY(rmp, ip);
/*
* acquire a transaction lock on the new right page
*rmpp = rmp;
- ip->i_blocks += LBLK2PBLK(ip->i_sb, lengthPXD(pxd));
return 0;
}
}
xlen = lengthPXD(&fp->header.self);
- ip->i_blocks -= LBLK2PBLK(ip->i_sb, xlen);
+
+ /* Free dlimit allocation. */
+ DLIMIT_FREE_BLOCK(ip, xlen);
+ /* Free quota allocation. */
+ DQUOT_FREE_BLOCK(ip, xlen);
/* free/invalidate its buffer page */
discard_metapage(fmp);
}
xlen = lengthPXD(&p->header.self);
- ip->i_blocks -= LBLK2PBLK(ip->i_sb, xlen);
+
+ /* Free dlimit allocation */
+ DLIMIT_FREE_BLOCK(ip, xlen);
+ /* Free quota allocation */
+ DQUOT_FREE_BLOCK(ip, xlen);
/* free/invalidate its buffer page */
discard_metapage(mp);
* the old directory table.
*/
if (DO_INDEX(ip)) {
- if (jfs_ip->next_index > (MAX_INLINE_DIRTABLE_ENTRY + 1)) {
+ if (!jfs_dirtable_inline(ip)) {
struct tblock *tblk = tid_to_tblock(tid);
/*
* We're playing games with the tid's xflag. If
/* init '..' entry */
p->header.idotdot = cpu_to_le32(idotdot);
-#if 0
- ip->i_blocks = LBLK2PBLK(ip->i_sb,
- ((jfs_ip->ea.flag & DXD_EXTENT) ?
- lengthDXD(&jfs_ip->ea) : 0) +
- ((jfs_ip->acl.flag & DXD_EXTENT) ?
- lengthDXD(&jfs_ip->acl) : 0));
-#endif
-
return;
}
ASSERT(p->header.flag & BT_LEAF);
tlck = txLock(tid, inode, mp, tlckDTREE | tlckENTRY);
+ if (BT_IS_ROOT(mp))
+ tlck->type |= tlckBTROOT;
+
dtlck = (struct dt_lock *) &tlck->lock;
stbl = DT_GETSTBL(p);
d = (struct ldtentry *) & p->slot[stbl[i]];
if (((long) jfs_dirent + d->namlen + 1) >
- (dirent_buf + PSIZE)) {
+ (dirent_buf + PAGE_SIZE)) {
/* DBCS codepages could overrun dirent_buf */
index = i;
overflow = 1;
dtpage_t * p, /* directory page */
int si)
{ /* entry slot index */
- wchar_t *kname, *name;
+ wchar_t *kname;
+ __le16 *name;
int klen, namlen, len, rc;
struct idtentry *ih;
struct dtslot *t;
int si, /* entry slot index */
int flag)
{
- wchar_t *kname, *name, x;
+ wchar_t *kname, x;
+ __le16 *name;
int klen, namlen, len, rc;
struct ldtentry *lh;
struct idtentry *ih;
struct idtentry *ih;
struct dtslot *t;
int namlen, len;
- wchar_t *name, *kname;
+ wchar_t *kname;
+ __le16 *name;
/* get entry */
stbl = DT_GETSTBL(p);
/*
* move head/only segment
*/
- UniStrncpy_le(kname, name, len);
+ UniStrncpy_from_le(kname, name, len);
/*
* move additional segment(s)
kname += len;
namlen -= len;
len = min(namlen, DTSLOTDATALEN);
- UniStrncpy_le(kname, t->name, len);
+ UniStrncpy_from_le(kname, t->name, len);
si = t->next;
}
struct ldtentry *lh = NULL;
struct idtentry *ih = NULL;
int hsi, fsi, klen, len, nextindex;
- wchar_t *kname, *name;
+ wchar_t *kname;
+ __le16 *name;
s8 *stbl;
pxd_t *xd;
struct dt_lock *dtlck = *dtlock;
if (p->header.flag & BT_LEAF) {
lh = (struct ldtentry *) h;
lh->next = h->next;
- lh->inumber = data->leaf.ino; /* little-endian */
+ lh->inumber = cpu_to_le32(data->leaf.ino);
lh->namlen = klen;
name = lh->name;
if (data->leaf.ip) {
len = min(klen, DTIHDRDATALEN);
}
- UniStrncpy_le(name, kname, len);
+ UniStrncpy_to_le(name, kname, len);
n = 1;
xsi = hsi;
kname += len;
len = min(klen, DTSLOTDATALEN);
- UniStrncpy_le(t->name, kname, len);
+ UniStrncpy_to_le(t->name, kname, len);
n++;
xsi = fsi;
d++;
len = min(snamlen, DTSLOTDATALEN);
- UniStrncpy(d->name, s->name, len);
+ UniStrncpy_le(d->name, s->name, len);
ns++;
nd++;
return 0;
}
-
-#ifdef _JFS_DEBUG_DTREE
-/*
- * dtDisplayTree()
- *
- * function: traverse forward
- */
-int dtDisplayTree(struct inode *ip)
-{
- int rc;
- struct metapage *mp;
- dtpage_t *p;
- s64 bn, pbn;
- int index, lastindex, v, h;
- pxd_t *xd;
- struct btstack btstack;
- struct btframe *btsp;
- struct btframe *parent;
- u8 *stbl;
- int psize = 256;
-
- printk("display B+-tree.\n");
-
- /* clear stack */
- btsp = btstack.stack;
-
- /*
- * start with root
- *
- * root resides in the inode
- */
- bn = 0;
- v = h = 0;
-
- /*
- * first access of each page:
- */
- newPage:
- DT_GETPAGE(ip, bn, mp, psize, p, rc);
- if (rc)
- return rc;
-
- /* process entries forward from first index */
- index = 0;
- lastindex = p->header.nextindex - 1;
-
- if (p->header.flag & BT_INTERNAL) {
- /*
- * first access of each internal page
- */
- printf("internal page ");
- dtDisplayPage(ip, bn, p);
-
- goto getChild;
- } else { /* (p->header.flag & BT_LEAF) */
-
- /*
- * first access of each leaf page
- */
- printf("leaf page ");
- dtDisplayPage(ip, bn, p);
-
- /*
- * process leaf page entries
- *
- for ( ; index <= lastindex; index++)
- {
- }
- */
-
- /* unpin the leaf page */
- DT_PUTPAGE(mp);
- }
-
- /*
- * go back up to the parent page
- */
- getParent:
- /* pop/restore parent entry for the current child page */
- if ((parent = (btsp == btstack.stack ? NULL : --btsp)) == NULL)
- /* current page must have been root */
- return;
-
- /*
- * parent page scan completed
- */
- if ((index = parent->index) == (lastindex = parent->lastindex)) {
- /* go back up to the parent page */
- goto getParent;
- }
-
- /*
- * parent page has entries remaining
- */
- /* get back the parent page */
- bn = parent->bn;
- /* v = parent->level; */
- DT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
- if (rc)
- return rc;
-
- /* get next parent entry */
- index++;
-
- /*
- * internal page: go down to child page of current entry
- */
- getChild:
- /* push/save current parent entry for the child page */
- btsp->bn = pbn = bn;
- btsp->index = index;
- btsp->lastindex = lastindex;
- /* btsp->level = v; */
- /* btsp->node = h; */
- ++btsp;
-
- /* get current entry for the child page */
- stbl = DT_GETSTBL(p);
- xd = (pxd_t *) & p->slot[stbl[index]];
-
- /*
- * first access of each internal entry:
- */
-
- /* get child page */
- bn = addressPXD(xd);
- psize = lengthPXD(xd) << ip->i_ipmnt->i_l2bsize;
-
- printk("traverse down 0x%Lx[%d]->0x%Lx\n", pbn, index, bn);
- v++;
- h = index;
-
- /* release parent page */
- DT_PUTPAGE(mp);
-
- /* process the child page */
- goto newPage;
-}
-
-
-/*
- * dtDisplayPage()
- *
- * function: display page
- */
-int dtDisplayPage(struct inode *ip, s64 bn, dtpage_t * p)
-{
- int rc;
- struct metapage *mp;
- struct ldtentry *lh;
- struct idtentry *ih;
- pxd_t *xd;
- int i, j;
- u8 *stbl;
- wchar_t name[JFS_NAME_MAX + 1];
- struct component_name key = { 0, name };
- int freepage = 0;
-
- if (p == NULL) {
- freepage = 1;
- DT_GETPAGE(ip, bn, mp, PSIZE, p, rc);
- if (rc)
- return rc;
- }
-
- /* display page control */
- printk("bn:0x%Lx flag:0x%08x nextindex:%d\n",
- bn, p->header.flag, p->header.nextindex);
-
- /* display entries */
- stbl = DT_GETSTBL(p);
- for (i = 0, j = 1; i < p->header.nextindex; i++, j++) {
- dtGetKey(p, i, &key, JFS_SBI(ip->i_sb)->mntflag);
- key.name[key.namlen] = '\0';
- if (p->header.flag & BT_LEAF) {
- lh = (struct ldtentry *) & p->slot[stbl[i]];
- printf("\t[%d] %s:%d", i, key.name,
- le32_to_cpu(lh->inumber));
- } else {
- ih = (struct idtentry *) & p->slot[stbl[i]];
- xd = (pxd_t *) ih;
- bn = addressPXD(xd);
- printf("\t[%d] %s:0x%Lx", i, key.name, bn);
- }
-
- if (j == 4) {
- printf("\n");
- j = 0;
- }
- }
-
- printf("\n");
-
- if (freepage)
- DT_PUTPAGE(mp);
-
- return 0;
-}
-#endif /* _JFS_DEBUG_DTREE */