ref: 44ce503a9ecea0e1793ee1c7917e65c0ae498f2c
parent: 449e753e691dd25706a8d46db41a84e27071320f
author: kvik <[email protected]>
date: Tue May 25 17:20:07 EDT 2021
Improve Qid mapping strategy and implementation
--- a/mkfile
+++ b/mkfile
@@ -8,6 +8,7 @@
unionfs.h
OFILES=\
util.$O\
+ qmap.$O\
unionfs.$O
</sys/src/cmd/mkone
--- a/unionfs.c
+++ b/unionfs.c
@@ -7,74 +7,9 @@
Union u0 = {.next = &u0, .prev = &u0};
Union *unionlist = &u0;
-QLock qidtablock;
-Qtab *qidtab[Nqtab];
F *root;
Srv thefs;
-int
-qthash(uvlong path)
-{
- int h, n;
-
- h = 0;
- for(n = 0; n < 64; n += Nqbit){
- h ^= path;
- path >>= Nqbit;
- }
- return h & (Nqtab-1);
-}
-
-uvlong
-uniqpath(uvlong path)
-{
- static u16int salt;
- int h, have;
- Qtab *q;
-
- for(;;){
- have = 0;
- h = qthash(path);
- for(q = qidtab[h]; q != nil; q = q->next)
- if(q->uniqpath == path){
- have = 1;
- break;
- }
- if(have == 0)
- return path;
- path = ((uvlong)salt<<48) | (path&((uvlong)1<<48)-1);
- ++salt;
- }
-}
-
-Qtab*
-qtadd(Dir *d)
-{
- int h;
- Qtab *q;
-
- qlock(&qidtablock);
- h = qthash(d->qid.path);
- for(q = qidtab[h]; q != nil; q = q->next)
- if(q->type == d->type
- && q->dev == d->dev
- && q->path == d->qid.path)
- goto done;
-
- q = emalloc(sizeof(*q));
- q->type = d->type;
- q->dev = d->dev;
- q->path = d->qid.path;
- q->uniqpath = uniqpath(q->path);
-
- h = qthash(q->path);
- q->next = qidtab[h];
- qidtab[h] = q;
-done:
- qunlock(&qidtablock);
- return q;
-}
-
void
unionlink(Union *p, Union *n)
{
@@ -92,9 +27,8 @@
f = emalloc(sizeof(*f));
f->ref = 1;
- f->qtab = qtadd(d);
f->Dir = *d;
- f->qid.path = f->qtab->uniqpath;
+ f->qid = qencode(d);
f->name = estrdup(d->name);
f->uid = estrdup(d->uid);
f->gid = estrdup(d->gid);
@@ -305,7 +239,7 @@
clone(Fid *old, Fid *new, void*)
{
Fstate *fs;
-
+
fs = old->aux;
new->aux = fstatenew(fs->file);
return nil;
--- a/unionfs.h
+++ b/unionfs.h
@@ -1,6 +1,4 @@
enum {
- Nqbit = 5,
- Nqtab = 1<<Nqbit,
Nftab = 32,
Nftlist = 32,
};
@@ -9,7 +7,6 @@
typedef struct F F;
typedef struct Ftab Ftab;
typedef struct Fstate Fstate;
-typedef struct Qtab Qtab;
struct Union {
char *root;
@@ -17,17 +14,9 @@
Union *prev, *next;
};
-struct Qtab {
- ushort type;
- uint dev;
- uvlong path, uniqpath;
- Qtab *next;
-};
-
struct F {
Ref;
Dir;
- Qtab *qtab;
char *path; /* real path */
char *fspath; /* internal path */
};
@@ -44,6 +33,7 @@
};
void usage(void);
+Qid qencode(Dir*);
char *mkpath(char*, ...);
Ref *copyref(Ref*);
void *emalloc(ulong);