Skip to content

Commit

Permalink
hashtable: new sig for vuht_add amd vuht_pathadd
Browse files Browse the repository at this point in the history
  • Loading branch information
rd235 committed Dec 28, 2024
1 parent f0d1083 commit 77bd0ce
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 39 deletions.
12 changes: 7 additions & 5 deletions include/vumodule.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,19 +168,21 @@ void VU_SYSNAME(name, cleanup) (uint8_t type, void *arg, int arglen, \
#define SET_EPOCH 1
#define NEGATIVE_MOUNT ((confirmfun_t)1)

#define VUFLAG_PERMANENT 1
#define VUFLAG_TRAILINGNUMBERS 2

typedef int (*confirmfun_t)(uint8_t type, void *arg, int arglen,
struct vuht_entry_t *ht);

struct vuht_entry_t *vuht_add(uint8_t type, const void *obj, int objlen,
struct vu_service_t *service, confirmfun_t confirmfun,
void *ht_private_data, int permanent);
struct vu_service_t *service, int vuflags,
confirmfun_t confirmfun, void *private_data);

struct vuht_entry_t *vuht_pathadd(uint8_t type, const char *source,
const char *path, const char *fstype,
unsigned long mountflags, const char *mountopts,
struct vu_service_t *service,
unsigned char trailingnumbers,
confirmfun_t confirmfun, void *ht_private_data);
struct vu_service_t *service, int vuflags,
confirmfun_t confirmfun, void *private_data);

#define BINFMTBUFLEN 128
#define BINFMTLINELEN 1920
Expand Down
2 changes: 1 addition & 1 deletion test_modules/netlinkdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void *vu_netlinkdump_init(void) {
vu_syscall_handler(s, close) = close;
#pragma GCC diagnostic pop

ht = vuht_add(CHECKSOCKET, &family, sizeof(int), s, NULL, NULL, 0);
ht = vuht_add(CHECKSOCKET, &family, sizeof(int), s, 0, NULL, NULL);
return NULL;
}

Expand Down
2 changes: 1 addition & 1 deletion test_modules/unrealcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void *vu_unrealcap_init(void) {
unsigned int i;
for (i = 0; i < VUSCLEN; i++) {
int vu_syscall = vu_arch_table[vusc[i]];
ht[i] = vuht_add(CHECKSC, &vu_syscall, sizeof(int), s, NULL, NULL, 0);
ht[i] = vuht_add(CHECKSC, &vu_syscall, sizeof(int), s, 0, NULL, NULL);
}
mod_inheritance_upcall_register(vu_cap_tracer_upcall);
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion test_modules/unrealprw.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
*/

/* this is a test module:
/* this is a test module: it is a copy of unreal supporting only pread/pwrite.
when loaded the entire file system "appears" as /unreal and /unreal/unreal.
$ vu_insmod unreal
Expand Down
2 changes: 1 addition & 1 deletion test_modules/unrealsock.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void *vu_unrealsock_init(void) {
#pragma GCC diagnostic pop

for (i = 0; i < 3; i++)
ht[i] = vuht_add(CHECKSOCKET, &afs[i], sizeof(int), s, NULL, NULL, 0);
ht[i] = vuht_add(CHECKSOCKET, &afs[i], sizeof(int), s, 0, NULL, NULL);
return NULL;
}

Expand Down
2 changes: 1 addition & 1 deletion test_modules/unrealuidgid.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ void *vu_unrealuidgid_init(void) {
unsigned int i;
for (i = 0; i < VUSCLEN; i++) {
int vu_syscall = vu_arch_table[vusc[i]];
ht[i] = vuht_add(CHECKSC, &vu_syscall, sizeof(int), s, NULL, NULL, 0);
ht[i] = vuht_add(CHECKSC, &vu_syscall, sizeof(int), s, 0, NULL, NULL);
}
mod_inheritance_upcall_register(vu_uid_gid_tracer_upcall);
return NULL;
Expand Down
10 changes: 6 additions & 4 deletions umvu/include/hashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ struct vu_service_t;
#define SET_EPOCH 1
#define NEGATIVE_MOUNT ((confirmfun_t)1)

#define VUFLAG_PERMANENT 1
#define VUFLAG_TRAILINGNUMBERS 2

/* hashtable elements may have exception. when a confirm function
is defined (as an argument adding the hashtable element) that
confirm function is called prior to confirm each match */
Expand All @@ -42,16 +45,15 @@ typedef int (*confirmfun_t)(uint8_t type, void *arg, int arglen,
/* add an element to the hashtable */
/* confirmfun is a cleanup function for CHECKMODULE */
struct vuht_entry_t *vuht_add(uint8_t type, const void *obj, int objlen,
struct vu_service_t *service, confirmfun_t confirmfun,
void *private_data, int permanent);
struct vu_service_t *service, int vuflags,
confirmfun_t confirmfun, void *private_data);

/* add a path element to the hashtable: This function is similar to vuht_add
* extra parameters are provided to generate teh mounttab line (see /proc/mounts) */
struct vuht_entry_t *vuht_pathadd(uint8_t type, const char *source,
const char *path, const char *fstype,
unsigned long mountflags, const char *mountopts,
struct vu_service_t *service,
unsigned char trailingnumbers,
struct vu_service_t *service, int vuflags,
confirmfun_t confirmfun, void *private_data);

/* del takes the element out from the data structure.... */
Expand Down
32 changes: 16 additions & 16 deletions umvu/src/hashtable.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct vuht_entry_t {
unsigned long mountflags;
epoch_t timestamp;
uint8_t type;
uint8_t trailingnumbers;
int vuflags;
struct vu_service_t *service;
struct vuht_entry_t *service_hte;
void *private_data;
Expand Down Expand Up @@ -269,7 +269,7 @@ static struct vuht_entry_t *vuht_internal_search(uint8_t type, void *obj,
while (ht != NULL) {
if (type == ht->type && sum == ht->hashsum &&
memcmp(obj, ht->obj, len) == 0 &&
(ht->trailingnumbers || !trailnum(objc)) &&
((ht->vuflags & VUFLAG_TRAILINGNUMBERS) || !trailnum(objc)) &&
(e = matching_epoch(ht->timestamp)) > 0) {
/*carrot add*/
if (ht->confirmfun == NEGATIVE_MOUNT)
Expand Down Expand Up @@ -329,13 +329,12 @@ static inline int stringobj(uint8_t type) {
type == CHECKFSALIAS;
}


static struct vuht_entry_t *
internal_vuht_add(uint8_t type, const void *obj, int objlen,
unsigned long mountflags, char *mtabline,
struct vu_service_t *service, uint8_t trailingnumbers,
confirmfun_t confirmfun, void *private_data,
int permanent)
{
struct vu_service_t *service, int vuflags,
confirmfun_t confirmfun, void *private_data) {
struct vuht_entry_t **hashhead;
struct vuht_entry_t *new = vuht_alloc();
/* create the entry and fill in the fields */
Expand All @@ -350,12 +349,12 @@ internal_vuht_add(uint8_t type, const void *obj, int objlen,
new->type = type;
new->mountflags = mountflags;
new->mtabline = mtabline;
new->trailingnumbers = trailingnumbers;
new->vuflags = vuflags;
new->private_data = private_data;
new->service = service;
new->service_hte = service->service_ht;
new->confirmfun = confirmfun;
new->count = (permanent != 0);
new->count = !! (vuflags & VUFLAG_PERMANENT);
if (service->service_ht)
vuht_pick_again(service->service_ht);

Expand Down Expand Up @@ -390,10 +389,10 @@ internal_vuht_add(uint8_t type, const void *obj, int objlen,
}

struct vuht_entry_t *vuht_add(uint8_t type, const void *obj, int objlen,
struct vu_service_t *service, confirmfun_t confirmfun,
void *private_data, int permanent) {
return internal_vuht_add(type, obj, objlen, 0, NULL, service, 1,
confirmfun, private_data, permanent);
struct vu_service_t *service, int vuflags,
confirmfun_t confirmfun, void *private_data) {
return internal_vuht_add(type, obj, objlen, 0, NULL, service, vuflags,
confirmfun, private_data);
}

static int permanent_mount(const char *opts)
Expand All @@ -409,8 +408,7 @@ static int permanent_mount(const char *opts)
struct vuht_entry_t *vuht_pathadd(uint8_t type, const char *source,
const char *path, const char *fstype,
unsigned long mountflags, const char *mountopts,
struct vu_service_t *service,
unsigned char trailingnumbers,
struct vu_service_t *service, int vuflags,
confirmfun_t confirmfun, void *private_data) {
char *mtabline;
const char *addpath;
Expand All @@ -433,9 +431,11 @@ struct vuht_entry_t *vuht_pathadd(uint8_t type, const char *source,
addpath = "";
else
addpath = path;
if (permanent_mount(mountopts))
vuflags |= VUFLAG_PERMANENT;
rv = internal_vuht_add(type, addpath, strlen(addpath), mountflags,
mtabline, service, trailingnumbers, confirmfun,
private_data, permanent_mount(mountopts));
mtabline, service, vuflags,
confirmfun, private_data);
if (rv == NULL && mtabline != NULL)
free(mtabline);
return rv;
Expand Down
3 changes: 2 additions & 1 deletion umvu/src/vu_vwrap_vumgmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ void vw_insmod(struct vuht_entry_t *ht, struct syscall_descriptor_t *sd) {
cleanup = module_getsym(service, "cleanup");
#pragma GCC diagnostic pop
sht = vuht_add(CHECKMODULE, modname, strlen(modname), service,
cleanup, NULL, permanent);
permanent ? VUFLAG_PERMANENT : 0,
cleanup, NULL);

service->service_ht = sht;

Expand Down
4 changes: 2 additions & 2 deletions vubinfmt/vubinfmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,10 @@ int vu_vubinfmt_mount(const char *source, const char *target,
switch(strcase(source)) {
case STRCASE(n,o,n,e):
case STRCASE(slash):
new->binfmt_ht = vuht_add(CHECKBINFMT, NULL, 0, s, vubinfmt_confirm, new, 0);
new->binfmt_ht = vuht_add(CHECKBINFMT, NULL, 0, s, 0, vubinfmt_confirm, new);
break;
default:
new->binfmt_ht = vuht_add(CHECKBINFMT, source, strlen(source), s, vubinfmt_confirm, new, 0);
new->binfmt_ht = vuht_add(CHECKBINFMT, source, strlen(source), s, 0, vubinfmt_confirm, new);
break;
}
new->path_ht = vuht_pathadd(CHECKPATH, source, target, filesystemtype, mountflags, data, s, 0, NULL, new);
Expand Down
6 changes: 3 additions & 3 deletions vudev/vudev.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,12 @@ int vu_vudev_mount(const char *source, const char *target,
goto err_init_null;
}
new->path_ht = vuht_pathadd(CHECKPATH, source, target, filesystemtype, mountflags,
data, s, 1, vudev_confirm_path, new);
data, s, VUFLAG_TRAILINGNUMBERS, vudev_confirm_path, new);
if (new->flags & VUDEVFLAGS_DEVID) {
if(S_ISCHR(new->stat.st_mode))
new->dev_ht = vuht_add(CHECKCHRDEVICE, NULL, 0, s, vudev_confirm_dev, new, 0);
new->dev_ht = vuht_add(CHECKCHRDEVICE, NULL, 0, s, 0, vudev_confirm_dev, new);
else if(S_ISBLK(new->stat.st_mode))
new->dev_ht = vuht_add(CHECKBLKDEVICE, NULL, 0, s, vudev_confirm_dev, new, 0);
new->dev_ht = vuht_add(CHECKBLKDEVICE, NULL, 0, s, 0, vudev_confirm_dev, new);
} else
new->dev_ht = NULL;
pthread_mutex_unlock(&(new->mutex));
Expand Down
2 changes: 1 addition & 1 deletion vumisc/vumisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ int vu_vumisc_mount(const char *source, const char *target,
pthread_mutex_lock(&(new->mutex));
new->path_ht = vuht_pathadd(CHECKPATH,
source, target, filesystemtype, mountflags, data, s, 0, NULL, new);
new->ops_ht = vuht_add(CHECKSC, NULL, 0, s, vumisc_confirm, new, 0);
new->ops_ht = vuht_add(CHECKSC, NULL, 0, s, 0, vumisc_confirm, new);
pthread_mutex_unlock(&(new->mutex));
return errno = 0, 0;
err_init_null:
Expand Down
4 changes: 2 additions & 2 deletions vunet/vunet.c
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,10 @@ int vu_vunet_mount(const char *source, const char *target,
retvalue = -1;
} else {
if (vunet->netops->supported_ioctl)
vunet->ioctl_ht = vuht_add(CHECKIOCTL, NULL, 0, s, checkioctl, vunet, 0);
vunet->ioctl_ht = vuht_add(CHECKIOCTL, NULL, 0, s, 0, checkioctl, vunet);
else
vunet->ioctl_ht = NULL;
vunet->socket_ht = vuht_add(CHECKSOCKET, NULL, 0, s, checksocket, vunet, 0);
vunet->socket_ht = vuht_add(CHECKSOCKET, NULL, 0, s, 0, checksocket, vunet);
vunet->path_ht = vuht_pathadd(CHECKPATH, source, target, filesystemtype, mountflags, data, s, 0, NULL, vunet);
printkdebug(N, "mount \'%s\' \'%s\' %s -> %p", source, target, filesystemtype, vunet);
}
Expand Down

0 comments on commit 77bd0ce

Please sign in to comment.