提交 2744a423 创建 作者: Nickolai Zeldovich's avatar Nickolai Zeldovich

double-int keys for dev/ino

上级 b635db5d
......@@ -101,18 +101,25 @@ void mpstartthem(void);
// ns.c
enum {
nskey_int = 1,
nskey_ii,
nskey_str,
nskey_iistr
};
struct nskey {
int type;
union {
uint i;
struct {
uint a;
uint b;
} ii;
char *s;
} u;
};
#define KI(v) (struct nskey){.type=nskey_int,.u.i=v}
#define KII(x,y) (struct nskey){.type=nskey_ii,.u.ii.a=x,.u.ii.b=y}
#define KS(v) (struct nskey){.type=nskey_str,.u.s=v}
void nsinit(void);
......
......@@ -143,7 +143,7 @@ iinit(void)
ip->inum = -i-1;
initlock(&ip->lock, "icache-lock");
initcondvar(&ip->cv, "icache-cv");
ns_insert(ins, KI(ip->inum), ip);
ns_insert(ins, KII(ip->dev, ip->inum), ip);
}
}
......@@ -230,9 +230,8 @@ iget(uint dev, uint inum)
retry:
// Try for cached inode.
rcu_begin_read();
ip = ns_lookup(ins, KI(inum)); // XXX ignore dev
ip = ns_lookup(ins, KII(dev, inum));
if (ip) {
if (ip->dev != dev) panic("iget dev mismatch");
// tricky: first bump ref, then check free flag
__sync_fetch_and_add(&ip->ref, 1);
if (ip->flags & I_FREE) {
......@@ -265,7 +264,7 @@ iget(uint dev, uint inum)
goto retry_evict;
}
release(&victim->lock);
ns_remove(ins, KI(victim->inum), victim);
ns_remove(ins, KII(victim->dev, victim->inum), victim);
rcu_delayed(victim, kmfree);
ip = kmalloc(sizeof(*ip));
......@@ -277,7 +276,7 @@ iget(uint dev, uint inum)
snprintf(ip->lockname, sizeof(ip->lockname), "cv:ino:%d", ip->inum);
initlock(&ip->lock, ip->lockname+3);
initcondvar(&ip->cv, ip->lockname);
if (ns_insert(ins, KI(ip->inum), ip) < 0) {
if (ns_insert(ins, KII(ip->dev, ip->inum), ip) < 0) {
rcu_delayed(ip, kmfree);
goto retry;
}
......
......@@ -19,6 +19,10 @@ struct elem {
struct elem * volatile next;
union {
uint ikey;
struct {
uint a;
uint b;
} iikey;
char skey[0];
};
};
......@@ -60,7 +64,10 @@ elemalloc(struct nskey *k)
int sz;
switch (k->type) {
case nskey_int:
sz = sizeof(*e);
sz = offsetof(struct elem, ikey) + sizeof(e->ikey);
break;
case nskey_ii:
sz = offsetof(struct elem, iikey) + sizeof(e->iikey);
break;
case nskey_str:
sz = offsetof(struct elem, skey) + strlen(k->u.s) + 1;
......@@ -82,6 +89,8 @@ h(struct nskey *k)
switch (k->type) {
case nskey_int:
return k->u.i % NHASH;
case nskey_ii:
return (k->u.ii.a ^ k->u.ii.b) % NHASH;
case nskey_str:
return k->u.s[0] % NHASH; // XXX
default:
......@@ -96,6 +105,10 @@ setkey(struct elem *e, struct nskey *k)
case nskey_int:
e->ikey = k->u.i;
break;
case nskey_ii:
e->iikey.a = k->u.ii.a;
e->iikey.b = k->u.ii.b;
break;
case nskey_str:
strncpy(e->skey, k->u.s, __INT_MAX__);
break;
......@@ -110,10 +123,10 @@ cmpkey(struct elem *e, struct nskey *k)
switch (k->type) {
case nskey_int:
return e->ikey == k->u.i;
break;
case nskey_ii:
return e->iikey.a == k->u.ii.a && e->iikey.b == k->u.ii.b;
case nskey_str:
return !strcmp(e->skey, k->u.s);
break;
default:
panic("key type");
}
......
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论