From e72fcd924b25b2b3b8a45c85d9c3d09388885249 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Mon, 19 Feb 2018 23:46:34 +0100 Subject: lib: Get RIB attributes from component This revises the RIB so it gets the complete file attribute list from the component instead of setting some attributes in the library. This will allow setting read/write access later on in the component itself. The time of last change of lsdb entries in the file system is now set to the time of the last received Link State Update for that entry. Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/lib/rib.c | 70 +++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 23 deletions(-) (limited to 'src/lib/rib.c') diff --git a/src/lib/rib.c b/src/lib/rib.c index 5bb8c1c3..947226a9 100644 --- a/src/lib/rib.c +++ b/src/lib/rib.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -155,9 +156,11 @@ static int rib_readdir(const char * path, ssize_t i; struct reg_comp * c; c = list_entry(p, struct reg_comp, next); - if (strcmp(path + 1, c->path) == 0) - if (c->ops->readdir == NULL) - break; + + if (strcmp(path + 1, c->path) != 0) + continue; + + assert(c->ops->readdir != NULL); len = c->ops->readdir(&dir_entries); if (len < 0) @@ -173,49 +176,70 @@ static int rib_readdir(const char * path, return 0; } +static size_t __getattr(const char * path, + struct stat * st) +{ + struct list_head * p; + char comp[RIB_PATH_LEN + 1]; + char * c; + + strcpy(comp, path + 1); + + c = strstr(comp, "/"); + + if (c != NULL) + *c = '\0'; + + pthread_rwlock_rdlock(&rib.lock); + + list_for_each(p, &rib.reg_comps) { + struct reg_comp * r = list_entry(p, struct reg_comp, next); + if (strcmp(comp, r->path) == 0) { + size_t ret = r->ops->getattr(c + 1, st); + pthread_rwlock_unlock(&rib.lock); + return ret; + } + } + + pthread_rwlock_unlock(&rib.lock); + + return -1; +} + static int rib_getattr(const char * path, struct stat * st) { struct list_head * p; struct timespec now; - clock_gettime(CLOCK_REALTIME_COARSE, &now); - memset(st, 0, sizeof(*st)); - if (strcmp(path, RT) == 0) { - st->st_mode = S_IFDIR | 0755; - st->st_nlink = 2; - st->st_uid = getuid(); - st->st_gid = getgid(); - st->st_mtime = now.tv_sec; - return 0; - } + if (strcmp(path, RT) == 0) + goto finish_dir; pthread_rwlock_rdlock(&rib.lock); list_for_each(p, &rib.reg_comps) { struct reg_comp * rc = list_entry(p, struct reg_comp, next); if (strcmp(path + 1, rc->path) == 0) { - st->st_mode = S_IFDIR | 0755; - st->st_nlink = 2; - break; + pthread_rwlock_unlock(&rib.lock); + goto finish_dir; } } pthread_rwlock_unlock(&rib.lock); - if (st->st_mode == 0) { - char buf[4096]; - st->st_nlink = 2; - st->st_mode = S_IFREG | 0755; - st->st_size = rib_read(path, buf, 4096, 0, NULL); - } + assert(st->st_mode == 0); + + return __getattr(path, st); + finish_dir: + clock_gettime(CLOCK_REALTIME_COARSE, &now); + st->st_mode = S_IFDIR | 0755; + st->st_nlink = 2; st->st_uid = getuid(); st->st_gid = getgid(); st->st_mtime = now.tv_sec; - return 0; } -- cgit v1.2.3