Lines Matching refs:section

59 	struct pt_section *section;  in pt_mk_section()  local
77 section = malloc(sizeof(*section)); in pt_mk_section()
78 if (!section) in pt_mk_section()
81 memset(section, 0, sizeof(*section)); in pt_mk_section()
83 section->filename = dupstr(filename); in pt_mk_section()
84 section->status = status; in pt_mk_section()
85 section->offset = offset; in pt_mk_section()
86 section->size = size; in pt_mk_section()
87 section->ucount = 1; in pt_mk_section()
91 errcode = mtx_init(&section->lock, mtx_plain); in pt_mk_section()
93 free(section->filename); in pt_mk_section()
94 free(section); in pt_mk_section()
98 errcode = mtx_init(&section->alock, mtx_plain); in pt_mk_section()
100 mtx_destroy(&section->lock); in pt_mk_section()
101 free(section->filename); in pt_mk_section()
102 free(section); in pt_mk_section()
108 return section; in pt_mk_section()
115 int pt_section_lock(struct pt_section *section) in pt_section_lock() argument
117 if (!section) in pt_section_lock()
124 errcode = mtx_lock(&section->lock); in pt_section_lock()
133 int pt_section_unlock(struct pt_section *section) in pt_section_unlock() argument
135 if (!section) in pt_section_unlock()
142 errcode = mtx_unlock(&section->lock); in pt_section_unlock()
151 static void pt_section_free(struct pt_section *section) in pt_section_free() argument
153 if (!section) in pt_section_free()
158 mtx_destroy(&section->alock); in pt_section_free()
159 mtx_destroy(&section->lock); in pt_section_free()
163 free(section->filename); in pt_section_free()
164 free(section->status); in pt_section_free()
165 free(section); in pt_section_free()
168 int pt_section_get(struct pt_section *section) in pt_section_get() argument
173 if (!section) in pt_section_get()
176 errcode = pt_section_lock(section); in pt_section_get()
180 ucount = section->ucount + 1; in pt_section_get()
182 (void) pt_section_unlock(section); in pt_section_get()
186 section->ucount = ucount; in pt_section_get()
188 return pt_section_unlock(section); in pt_section_get()
191 int pt_section_put(struct pt_section *section) in pt_section_put() argument
196 if (!section) in pt_section_put()
199 errcode = pt_section_lock(section); in pt_section_put()
203 mcount = section->mcount; in pt_section_put()
204 ucount = section->ucount; in pt_section_put()
206 section->ucount = ucount - 1; in pt_section_put()
207 return pt_section_unlock(section); in pt_section_put()
210 errcode = pt_section_unlock(section); in pt_section_put()
217 pt_section_free(section); in pt_section_put()
221 static int pt_section_lock_attach(struct pt_section *section) in pt_section_lock_attach() argument
223 if (!section) in pt_section_lock_attach()
230 errcode = mtx_lock(&section->alock); in pt_section_lock_attach()
239 static int pt_section_unlock_attach(struct pt_section *section) in pt_section_unlock_attach() argument
241 if (!section) in pt_section_unlock_attach()
248 errcode = mtx_unlock(&section->alock); in pt_section_unlock_attach()
257 int pt_section_attach(struct pt_section *section, in pt_section_attach() argument
263 if (!section || !iscache) in pt_section_attach()
266 errcode = pt_section_lock_attach(section); in pt_section_attach()
270 ucount = section->ucount; in pt_section_attach()
271 acount = section->acount; in pt_section_attach()
273 if (section->iscache || !ucount) in pt_section_attach()
276 section->iscache = iscache; in pt_section_attach()
277 section->acount = 1; in pt_section_attach()
279 return pt_section_unlock_attach(section); in pt_section_attach()
284 (void) pt_section_unlock_attach(section); in pt_section_attach()
291 if (section->iscache != iscache) in pt_section_attach()
294 section->acount = acount; in pt_section_attach()
296 return pt_section_unlock_attach(section); in pt_section_attach()
299 (void) pt_section_unlock_attach(section); in pt_section_attach()
303 int pt_section_detach(struct pt_section *section, in pt_section_detach() argument
309 if (!section || !iscache) in pt_section_detach()
312 errcode = pt_section_lock_attach(section); in pt_section_detach()
316 if (section->iscache != iscache) in pt_section_detach()
319 acount = section->acount; in pt_section_detach()
324 ucount = section->ucount; in pt_section_detach()
328 section->acount = acount; in pt_section_detach()
330 section->iscache = NULL; in pt_section_detach()
332 return pt_section_unlock_attach(section); in pt_section_detach()
335 (void) pt_section_unlock_attach(section); in pt_section_detach()
339 const char *pt_section_filename(const struct pt_section *section) in pt_section_filename() argument
341 if (!section) in pt_section_filename()
344 return section->filename; in pt_section_filename()
347 uint64_t pt_section_size(const struct pt_section *section) in pt_section_size() argument
349 if (!section) in pt_section_size()
352 return section->size; in pt_section_size()
355 static int pt_section_bcache_memsize(const struct pt_section *section, in pt_section_bcache_memsize() argument
360 if (!section || !psize) in pt_section_bcache_memsize()
363 bcache = section->bcache; in pt_section_bcache_memsize()
375 static int pt_section_memsize_locked(const struct pt_section *section, in pt_section_memsize_locked() argument
379 int (*memsize)(const struct pt_section *section, uint64_t *size); in pt_section_memsize_locked()
382 if (!section || !psize) in pt_section_memsize_locked()
385 memsize = section->memsize; in pt_section_memsize_locked()
387 if (section->mcount) in pt_section_memsize_locked()
394 errcode = memsize(section, &msize); in pt_section_memsize_locked()
398 errcode = pt_section_bcache_memsize(section, &bcsize); in pt_section_memsize_locked()
407 int pt_section_memsize(struct pt_section *section, uint64_t *size) in pt_section_memsize() argument
411 errcode = pt_section_lock(section); in pt_section_memsize()
415 status = pt_section_memsize_locked(section, size); in pt_section_memsize()
417 errcode = pt_section_unlock(section); in pt_section_memsize()
424 uint64_t pt_section_offset(const struct pt_section *section) in pt_section_offset() argument
426 if (!section) in pt_section_offset()
429 return section->offset; in pt_section_offset()
432 int pt_section_alloc_bcache(struct pt_section *section) in pt_section_alloc_bcache() argument
440 if (!section) in pt_section_alloc_bcache()
443 if (!section->mcount) in pt_section_alloc_bcache()
446 ssize = pt_section_size(section); in pt_section_alloc_bcache()
462 errcode = pt_section_lock_attach(section); in pt_section_alloc_bcache()
466 errcode = pt_section_lock(section); in pt_section_alloc_bcache()
470 bcache = pt_section_bcache(section); in pt_section_alloc_bcache()
488 section->bcache = bcache; in pt_section_alloc_bcache()
490 errcode = pt_section_memsize_locked(section, &memsize); in pt_section_alloc_bcache()
494 errcode = pt_section_unlock(section); in pt_section_alloc_bcache()
499 iscache = section->iscache; in pt_section_alloc_bcache()
501 errcode = pt_iscache_notify_resize(iscache, section, in pt_section_alloc_bcache()
508 return pt_section_unlock_attach(section); in pt_section_alloc_bcache()
512 (void) pt_section_unlock(section); in pt_section_alloc_bcache()
515 (void) pt_section_unlock_attach(section); in pt_section_alloc_bcache()
519 int pt_section_on_map_lock(struct pt_section *section) in pt_section_on_map_lock() argument
524 if (!section) in pt_section_on_map_lock()
527 errcode = pt_section_lock_attach(section); in pt_section_on_map_lock()
531 iscache = section->iscache; in pt_section_on_map_lock()
533 return pt_section_unlock_attach(section); in pt_section_on_map_lock()
542 status = pt_iscache_notify_map(iscache, section); in pt_section_on_map_lock()
544 errcode = pt_section_unlock_attach(section); in pt_section_on_map_lock()
551 int pt_section_map_share(struct pt_section *section) in pt_section_map_share() argument
556 if (!section) in pt_section_map_share()
559 errcode = pt_section_lock(section); in pt_section_map_share()
563 mcount = section->mcount; in pt_section_map_share()
565 (void) pt_section_unlock(section); in pt_section_map_share()
571 (void) pt_section_unlock(section); in pt_section_map_share()
575 section->mcount = mcount; in pt_section_map_share()
577 return pt_section_unlock(section); in pt_section_map_share()
580 int pt_section_unmap(struct pt_section *section) in pt_section_unmap() argument
585 if (!section) in pt_section_unmap()
588 errcode = pt_section_lock(section); in pt_section_unmap()
592 mcount = section->mcount; in pt_section_unmap()
598 section->mcount = mcount -= 1; in pt_section_unmap()
600 return pt_section_unlock(section); in pt_section_unmap()
603 if (!section->unmap) in pt_section_unmap()
606 status = section->unmap(section); in pt_section_unmap()
608 pt_bcache_free(section->bcache); in pt_section_unmap()
609 section->bcache = NULL; in pt_section_unmap()
611 errcode = pt_section_unlock(section); in pt_section_unmap()
618 (void) pt_section_unlock(section); in pt_section_unmap()
622 int pt_section_read(const struct pt_section *section, uint8_t *buffer, in pt_section_read() argument
627 if (!section) in pt_section_read()
630 if (!section->read) in pt_section_read()
633 limit = section->size; in pt_section_read()
642 return section->read(section, buffer, size, offset); in pt_section_read()