Lines Matching full:section
43 struct pt_section *section; in pt_mk_section() local
80 section = malloc(sizeof(*section)); in pt_mk_section()
81 if (!section) { in pt_mk_section()
86 memset(section, 0, sizeof(*section)); in pt_mk_section()
88 section->filename = fname; in pt_mk_section()
89 section->status = status; in pt_mk_section()
90 section->offset = offset; in pt_mk_section()
91 section->size = size; in pt_mk_section()
92 section->ucount = 1; in pt_mk_section()
96 errcode = mtx_init(§ion->lock, mtx_plain); in pt_mk_section()
98 free(section); in pt_mk_section()
104 errcode = mtx_init(§ion->alock, mtx_plain); in pt_mk_section()
106 mtx_destroy(§ion->lock); in pt_mk_section()
107 free(section); in pt_mk_section()
115 *psection = section; in pt_mk_section()
126 int pt_section_lock(struct pt_section *section) in pt_section_lock() argument
128 if (!section) in pt_section_lock()
135 errcode = mtx_lock(§ion->lock); in pt_section_lock()
144 int pt_section_unlock(struct pt_section *section) in pt_section_unlock() argument
146 if (!section) in pt_section_unlock()
153 errcode = mtx_unlock(§ion->lock); in pt_section_unlock()
162 static void pt_section_free(struct pt_section *section) in pt_section_free() argument
164 if (!section) in pt_section_free()
169 mtx_destroy(§ion->alock); in pt_section_free()
170 mtx_destroy(§ion->lock); in pt_section_free()
174 free(section->filename); in pt_section_free()
175 free(section->status); in pt_section_free()
176 free(section); in pt_section_free()
179 int pt_section_get(struct pt_section *section) in pt_section_get() argument
184 if (!section) in pt_section_get()
187 errcode = pt_section_lock(section); in pt_section_get()
191 ucount = section->ucount + 1; in pt_section_get()
193 (void) pt_section_unlock(section); in pt_section_get()
197 section->ucount = ucount; in pt_section_get()
199 return pt_section_unlock(section); in pt_section_get()
202 int pt_section_put(struct pt_section *section) in pt_section_put() argument
207 if (!section) in pt_section_put()
210 errcode = pt_section_lock(section); in pt_section_put()
214 mcount = section->mcount; in pt_section_put()
215 ucount = section->ucount; in pt_section_put()
217 section->ucount = ucount - 1; in pt_section_put()
218 return pt_section_unlock(section); in pt_section_put()
221 errcode = pt_section_unlock(section); in pt_section_put()
228 pt_section_free(section); in pt_section_put()
232 static int pt_section_lock_attach(struct pt_section *section) in pt_section_lock_attach() argument
234 if (!section) in pt_section_lock_attach()
241 errcode = mtx_lock(§ion->alock); in pt_section_lock_attach()
250 static int pt_section_unlock_attach(struct pt_section *section) in pt_section_unlock_attach() argument
252 if (!section) in pt_section_unlock_attach()
259 errcode = mtx_unlock(§ion->alock); in pt_section_unlock_attach()
268 int pt_section_attach(struct pt_section *section, in pt_section_attach() argument
274 if (!section || !iscache) in pt_section_attach()
277 errcode = pt_section_lock_attach(section); in pt_section_attach()
281 ucount = section->ucount; in pt_section_attach()
282 acount = section->acount; in pt_section_attach()
284 if (section->iscache || !ucount) in pt_section_attach()
287 section->iscache = iscache; in pt_section_attach()
288 section->acount = 1; in pt_section_attach()
290 return pt_section_unlock_attach(section); in pt_section_attach()
295 (void) pt_section_unlock_attach(section); in pt_section_attach()
302 if (section->iscache != iscache) in pt_section_attach()
305 section->acount = acount; in pt_section_attach()
307 return pt_section_unlock_attach(section); in pt_section_attach()
310 (void) pt_section_unlock_attach(section); in pt_section_attach()
314 int pt_section_detach(struct pt_section *section, in pt_section_detach() argument
320 if (!section || !iscache) in pt_section_detach()
323 errcode = pt_section_lock_attach(section); in pt_section_detach()
327 if (section->iscache != iscache) in pt_section_detach()
330 acount = section->acount; in pt_section_detach()
335 ucount = section->ucount; in pt_section_detach()
339 section->acount = acount; in pt_section_detach()
341 section->iscache = NULL; in pt_section_detach()
343 return pt_section_unlock_attach(section); in pt_section_detach()
346 (void) pt_section_unlock_attach(section); in pt_section_detach()
350 const char *pt_section_filename(const struct pt_section *section) in pt_section_filename() argument
352 if (!section) in pt_section_filename()
355 return section->filename; in pt_section_filename()
358 uint64_t pt_section_size(const struct pt_section *section) in pt_section_size() argument
360 if (!section) in pt_section_size()
363 return section->size; in pt_section_size()
366 static int pt_section_bcache_memsize(const struct pt_section *section, in pt_section_bcache_memsize() argument
371 if (!section || !psize) in pt_section_bcache_memsize()
374 bcache = section->bcache; in pt_section_bcache_memsize()
386 static int pt_section_memsize_locked(const struct pt_section *section, in pt_section_memsize_locked() argument
390 int (*memsize)(const struct pt_section *section, uint64_t *size); in pt_section_memsize_locked()
393 if (!section || !psize) in pt_section_memsize_locked()
396 memsize = section->memsize; in pt_section_memsize_locked()
398 if (section->mcount) in pt_section_memsize_locked()
405 errcode = memsize(section, &msize); in pt_section_memsize_locked()
409 errcode = pt_section_bcache_memsize(section, &bcsize); in pt_section_memsize_locked()
418 int pt_section_memsize(struct pt_section *section, uint64_t *size) in pt_section_memsize() argument
422 errcode = pt_section_lock(section); in pt_section_memsize()
426 status = pt_section_memsize_locked(section, size); in pt_section_memsize()
428 errcode = pt_section_unlock(section); in pt_section_memsize()
435 uint64_t pt_section_offset(const struct pt_section *section) in pt_section_offset() argument
437 if (!section) in pt_section_offset()
440 return section->offset; in pt_section_offset()
443 int pt_section_alloc_bcache(struct pt_section *section) in pt_section_alloc_bcache() argument
451 if (!section) in pt_section_alloc_bcache()
454 if (!section->mcount) in pt_section_alloc_bcache()
457 ssize = pt_section_size(section); in pt_section_alloc_bcache()
465 /* We need to take both the attach and the section lock in order to pair in pt_section_alloc_bcache()
473 errcode = pt_section_lock_attach(section); in pt_section_alloc_bcache()
477 errcode = pt_section_lock(section); in pt_section_alloc_bcache()
481 bcache = pt_section_bcache(section); in pt_section_alloc_bcache()
499 section->bcache = bcache; in pt_section_alloc_bcache()
501 errcode = pt_section_memsize_locked(section, &memsize); in pt_section_alloc_bcache()
505 errcode = pt_section_unlock(section); in pt_section_alloc_bcache()
510 iscache = section->iscache; in pt_section_alloc_bcache()
512 errcode = pt_iscache_notify_resize(iscache, section, in pt_section_alloc_bcache()
519 return pt_section_unlock_attach(section); in pt_section_alloc_bcache()
523 (void) pt_section_unlock(section); in pt_section_alloc_bcache()
526 (void) pt_section_unlock_attach(section); in pt_section_alloc_bcache()
530 int pt_section_on_map_lock(struct pt_section *section) in pt_section_on_map_lock() argument
535 if (!section) in pt_section_on_map_lock()
538 errcode = pt_section_lock_attach(section); in pt_section_on_map_lock()
542 iscache = section->iscache; in pt_section_on_map_lock()
544 return pt_section_unlock_attach(section); in pt_section_on_map_lock()
546 /* There is a potential deadlock when @section was unmapped again and in pt_section_on_map_lock()
553 status = pt_iscache_notify_map(iscache, section); in pt_section_on_map_lock()
555 errcode = pt_section_unlock_attach(section); in pt_section_on_map_lock()
562 int pt_section_map_share(struct pt_section *section) in pt_section_map_share() argument
567 if (!section) in pt_section_map_share()
570 errcode = pt_section_lock(section); in pt_section_map_share()
574 mcount = section->mcount; in pt_section_map_share()
576 (void) pt_section_unlock(section); in pt_section_map_share()
582 (void) pt_section_unlock(section); in pt_section_map_share()
586 section->mcount = mcount; in pt_section_map_share()
588 return pt_section_unlock(section); in pt_section_map_share()
591 int pt_section_unmap(struct pt_section *section) in pt_section_unmap() argument
596 if (!section) in pt_section_unmap()
599 errcode = pt_section_lock(section); in pt_section_unmap()
603 mcount = section->mcount; in pt_section_unmap()
609 section->mcount = mcount -= 1; in pt_section_unmap()
611 return pt_section_unlock(section); in pt_section_unmap()
614 if (!section->unmap) in pt_section_unmap()
617 status = section->unmap(section); in pt_section_unmap()
619 pt_bcache_free(section->bcache); in pt_section_unmap()
620 section->bcache = NULL; in pt_section_unmap()
622 errcode = pt_section_unlock(section); in pt_section_unmap()
629 (void) pt_section_unlock(section); in pt_section_unmap()
633 int pt_section_read(const struct pt_section *section, uint8_t *buffer, in pt_section_read() argument
638 if (!section) in pt_section_read()
641 if (!section->read) in pt_section_read()
644 limit = section->size; in pt_section_read()
648 /* Truncate if we try to read past the end of the section. */ in pt_section_read()
653 return section->read(section, buffer, size, offset); in pt_section_read()