diff options
author | sjg <sjg@FreeBSD.org> | 2014-11-19 01:07:58 +0000 |
---|---|---|
committer | sjg <sjg@FreeBSD.org> | 2014-11-19 01:07:58 +0000 |
commit | b137080f19736ee33fede2e88bb54438604cf86b (patch) | |
tree | 377ac0ac449528621eb192cd245adadb5fd53668 /lib/libcuse | |
parent | ab21a29eb607d4dfe389b965fbdee27558e791aa (diff) | |
parent | 4a8d07956d121238d006d34ffe7d6269744e8b1a (diff) | |
download | FreeBSD-src-b137080f19736ee33fede2e88bb54438604cf86b.zip FreeBSD-src-b137080f19736ee33fede2e88bb54438604cf86b.tar.gz |
Merge from head@274682
Diffstat (limited to 'lib/libcuse')
-rw-r--r-- | lib/libcuse/Makefile | 1 | ||||
-rw-r--r-- | lib/libcuse/cuse_lib.c | 98 |
2 files changed, 50 insertions, 49 deletions
diff --git a/lib/libcuse/Makefile b/lib/libcuse/Makefile index 6269cbe..2d1ded5 100644 --- a/lib/libcuse/Makefile +++ b/lib/libcuse/Makefile @@ -36,6 +36,7 @@ CFLAGS+= -D_GNU_SOURCE CFLAGS+= -g CFLAGS+= -DHAVE_DEBUG .endif +DPADD+= ${LIBPTHREAD} LDADD+= ${PTHREAD_LIBS} MLINKS= diff --git a/lib/libcuse/cuse_lib.c b/lib/libcuse/cuse_lib.c index 9d8352f..321522d 100644 --- a/lib/libcuse/cuse_lib.c +++ b/lib/libcuse/cuse_lib.c @@ -79,23 +79,19 @@ struct cuse_dev { void *priv1; }; -static TAILQ_HEAD(, cuse_dev) h_cuse; -static TAILQ_HEAD(, cuse_dev_entered) h_cuse_entered; static int f_cuse = -1; + static pthread_mutex_t m_cuse; -static struct cuse_vm_allocation a_cuse[CUSE_ALLOC_UNIT_MAX]; +static TAILQ_HEAD(, cuse_dev) h_cuse __guarded_by(m_cuse); +static TAILQ_HEAD(, cuse_dev_entered) h_cuse_entered __guarded_by(m_cuse); +static struct cuse_vm_allocation a_cuse[CUSE_ALLOC_UNIT_MAX] + __guarded_by(m_cuse); -static void -cuse_lock(void) -{ - pthread_mutex_lock(&m_cuse); -} +#define CUSE_LOCK() \ + pthread_mutex_lock(&m_cuse) -static void -cuse_unlock(void) -{ - pthread_mutex_unlock(&m_cuse); -} +#define CUSE_UNLOCK() \ + pthread_mutex_unlock(&m_cuse) int cuse_init(void) @@ -148,7 +144,7 @@ cuse_vmoffset(void *_ptr) unsigned long remainder; int n; - cuse_lock(); + CUSE_LOCK(); for (n = 0; n != CUSE_ALLOC_UNIT_MAX; n++) { if (a_cuse[n].ptr == NULL) continue; @@ -158,7 +154,7 @@ cuse_vmoffset(void *_ptr) if ((ptr >= ptr_min) && (ptr <= ptr_max)) { - cuse_unlock(); + CUSE_UNLOCK(); remainder = (ptr - ptr_min); @@ -167,7 +163,7 @@ cuse_vmoffset(void *_ptr) return ((n * PAGE_SIZE * CUSE_ALLOC_PAGES_MAX) + remainder); } } - cuse_unlock(); + CUSE_UNLOCK(); return (0x80000000UL); /* failure */ } @@ -190,7 +186,7 @@ cuse_vmalloc(int size) info.page_count = (size + PAGE_SIZE - 1) / PAGE_SIZE; - cuse_lock(); + CUSE_LOCK(); for (n = 0; n != CUSE_ALLOC_UNIT_MAX; n++) { if (a_cuse[n].ptr != NULL) @@ -199,7 +195,7 @@ cuse_vmalloc(int size) a_cuse[n].ptr = ((uint8_t *)1); /* reserve */ a_cuse[n].size = 0; - cuse_unlock(); + CUSE_UNLOCK(); info.alloc_nr = n; @@ -207,7 +203,7 @@ cuse_vmalloc(int size) if (error) { - cuse_lock(); + CUSE_LOCK(); a_cuse[n].ptr = NULL; @@ -228,20 +224,20 @@ cuse_vmalloc(int size) if (error) { /* ignore */ } - cuse_lock(); + CUSE_LOCK(); a_cuse[n].ptr = NULL; break; } - cuse_lock(); + CUSE_LOCK(); a_cuse[n].ptr = ptr; a_cuse[n].size = size; - cuse_unlock(); + CUSE_UNLOCK(); return (ptr); /* success */ } - cuse_unlock(); + CUSE_UNLOCK(); return (NULL); /* failure */ } @@ -253,12 +249,12 @@ cuse_is_vmalloc_addr(void *ptr) if (f_cuse < 0 || ptr == NULL) return (0); /* false */ - cuse_lock(); + CUSE_LOCK(); for (n = 0; n != CUSE_ALLOC_UNIT_MAX; n++) { if (a_cuse[n].ptr == ptr) break; } - cuse_unlock(); + CUSE_UNLOCK(); return (n != CUSE_ALLOC_UNIT_MAX); } @@ -266,6 +262,7 @@ cuse_is_vmalloc_addr(void *ptr) void cuse_vmfree(void *ptr) { + struct cuse_vm_allocation temp; struct cuse_alloc_info info; int error; int n; @@ -273,32 +270,35 @@ cuse_vmfree(void *ptr) if (f_cuse < 0) return; - memset(&info, 0, sizeof(info)); - - cuse_lock(); + CUSE_LOCK(); for (n = 0; n != CUSE_ALLOC_UNIT_MAX; n++) { if (a_cuse[n].ptr != ptr) continue; - cuse_unlock(); + temp = a_cuse[n]; - info.alloc_nr = n; + CUSE_UNLOCK(); + + munmap(temp.ptr, temp.size); - munmap(ptr, a_cuse[n].size); + memset(&info, 0, sizeof(info)); + + info.alloc_nr = n; error = ioctl(f_cuse, CUSE_IOCTL_FREE_MEMORY, &info); - if (error) { - /* ignore */ + if (error != 0) { + /* ignore any errors */ + DPRINTF("Freeing memory failed: %d\n", errno); } - cuse_lock(); + CUSE_LOCK(); a_cuse[n].ptr = NULL; a_cuse[n].size = 0; break; } - cuse_unlock(); + CUSE_UNLOCK(); } int @@ -405,9 +405,9 @@ cuse_dev_create(const struct cuse_methods *mtod, void *priv0, void *priv1, free(cdev); return (NULL); } - cuse_lock(); + CUSE_LOCK(); TAILQ_INSERT_TAIL(&h_cuse, cdev, entry); - cuse_unlock(); + CUSE_UNLOCK(); return (cdev); } @@ -421,9 +421,9 @@ cuse_dev_destroy(struct cuse_dev *cdev) if (f_cuse < 0) return; - cuse_lock(); + CUSE_LOCK(); TAILQ_REMOVE(&h_cuse, cdev, entry); - cuse_unlock(); + CUSE_UNLOCK(); error = ioctl(f_cuse, CUSE_IOCTL_DESTROY_DEV, &cdev); if (error) @@ -475,7 +475,7 @@ cuse_wait_and_process(void) cdev = info.dev; - cuse_lock(); + CUSE_LOCK(); enter.thread = curr; enter.per_file_handle = (void *)info.per_file_handle; enter.cmd = info.command; @@ -483,7 +483,7 @@ cuse_wait_and_process(void) enter.got_signal = 0; enter.cdev = cdev; TAILQ_INSERT_TAIL(&h_cuse_entered, &enter, entry); - cuse_unlock(); + CUSE_UNLOCK(); DPRINTF("cuse: Command = %d = %s, flags = %d, arg = 0x%08x, ptr = 0x%08x\n", (int)info.command, cuse_cmd_str(info.command), (int)info.fflags, @@ -505,7 +505,7 @@ cuse_wait_and_process(void) error = 0; - cuse_lock(); + CUSE_LOCK(); TAILQ_FOREACH(pe, &h_cuse_entered, entry) { if (pe->cdev != cdev) continue; @@ -518,7 +518,7 @@ cuse_wait_and_process(void) pthread_kill(pe->thread, SIGHUP); error = CUSE_ERR_BUSY; } - cuse_unlock(); + CUSE_UNLOCK(); if (error == 0) break; @@ -569,7 +569,7 @@ cuse_wait_and_process(void) break; case CUSE_CMD_SIGNAL: - cuse_lock(); + CUSE_LOCK(); TAILQ_FOREACH(pe, &h_cuse_entered, entry) { if (pe->cdev != cdev) continue; @@ -581,7 +581,7 @@ cuse_wait_and_process(void) pe->got_signal = 1; pthread_kill(pe->thread, SIGHUP); } - cuse_unlock(); + CUSE_UNLOCK(); break; default: @@ -592,9 +592,9 @@ cuse_wait_and_process(void) DPRINTF("cuse: Command error = %d for %s\n", error, cuse_cmd_str(info.command)); - cuse_lock(); + CUSE_LOCK(); TAILQ_REMOVE(&h_cuse_entered, &enter, entry); - cuse_unlock(); + CUSE_UNLOCK(); /* we ignore any sync command failures */ ioctl(f_cuse, CUSE_IOCTL_SYNC_COMMAND, &error); @@ -608,12 +608,12 @@ cuse_dev_get_entered(void) struct cuse_dev_entered *pe; pthread_t curr = pthread_self(); - cuse_lock(); + CUSE_LOCK(); TAILQ_FOREACH(pe, &h_cuse_entered, entry) { if (pe->thread == curr) break; } - cuse_unlock(); + CUSE_UNLOCK(); return (pe); } |