]> git.proxmox.com Git - mirror_lxcfs.git/commitdiff
Claim and use load_free() to free hash table.
authorzhang2639 <zhangshiqiang@hust.edu.cn>
Thu, 24 May 2018 10:46:53 +0000 (18:46 +0800)
committerzhang2639 <zhangshiqiang@hust.edu.cn>
Thu, 24 May 2018 10:46:53 +0000 (18:46 +0800)
Signed-off-by: zhang2639 <zhangshiqiang@hust.edu.cn>
Signed-off-by: yuwang <yuwang@linux.alibaba.com>
bindings.c
bindings.h
lxcfs.c

index b08cf43e725d38ccf0608dcfda4d91a36c35c3a1..b20eaa053b92877683163a27206143c8c9eed36a 100644 (file)
@@ -247,6 +247,38 @@ static struct load_node *del_node(struct load_node *n, int locate)
        return g;
 }
 
+void load_free(void)
+{
+       int i;
+       struct load_node *f, *p;
+
+       for (i = 0; i < LOAD_SIZE; i++) {
+               pthread_mutex_lock(&load_hash[i].lock);
+               pthread_rwlock_wrlock(&load_hash[i].rilock);
+               pthread_rwlock_wrlock(&load_hash[i].rdlock);
+               if (load_hash[i].next == NULL) {
+                       pthread_mutex_unlock(&load_hash[i].lock);
+                       pthread_mutex_destroy(&load_hash[i].lock);
+                       pthread_rwlock_unlock(&load_hash[i].rilock);
+                       pthread_rwlock_destroy(&load_hash[i].rilock);
+                       pthread_rwlock_unlock(&load_hash[i].rdlock);
+                       pthread_rwlock_destroy(&load_hash[i].rdlock);
+                       continue;
+               }
+               for (f = load_hash[i].next; f; ) {
+                       free(f->cg);
+                       p = f->next;
+                       free(f);
+                       f = p;
+               }
+               pthread_mutex_unlock(&load_hash[i].lock);
+               pthread_mutex_destroy(&load_hash[i].lock);
+               pthread_rwlock_unlock(&load_hash[i].rilock);
+               pthread_rwlock_destroy(&load_hash[i].rilock);
+               pthread_rwlock_unlock(&load_hash[i].rdlock);
+               pthread_rwlock_destroy(&load_hash[i].rdlock);
+       }
+}
 /* Reserve buffer size to account for file size changes. */
 #define BUF_RESERVE_SIZE 512
 
index a34ac5fa964d2bd05114280936cd2ca331c2244c..65630114029578df0f1bb3ce7d0847020ecba638 100644 (file)
@@ -33,5 +33,6 @@ extern int proc_read(const char *path, char *buf, size_t size, off_t offset,
                struct fuse_file_info *fi);
 extern int proc_access(const char *path, int mask);
 extern pthread_t load_daemon(int load_use);
+extern void load_free(void);
 
 #endif /* __LXCFS_BINDINGS_H */
diff --git a/lxcfs.c b/lxcfs.c
index fe9c250ea057e2714997b90090f6826a748c152b..fe381480ca3059097becf15415006cb4894f51fa 100644 (file)
--- a/lxcfs.c
+++ b/lxcfs.c
@@ -937,6 +937,27 @@ int main(int argc, char *argv[])
        }
        if (!fuse_main(nargs, newargv, &lxcfs_ops, NULL))
                ret = EXIT_SUCCESS;
+       if (load_use == true) {
+               s = pthread_cancel(pid);
+               if (s == 0) {
+                       s = pthread_join(pid, NULL); /* Make sure sub thread has been canceled. */
+                       if (s != 0) {
+                               lxcfs_error("%s\n", "load_free error!");
+                               goto out;
+                       }
+                       dlerror();    /* Clear any existing error */
+
+                       load_free = (void (*)(void)) dlsym(dlopen_handle, "load_free");
+                       error = dlerror();
+                       if (error != NULL) {
+                               lxcfs_error("load_free error: %s\n", error);
+                               goto out;
+                       }
+                       load_free();
+               } else {
+                       lxcfs_error("%s\n", "load_free error!");
+               }
+       }
 
 out:
        if (dlopen_handle)