Blame


1 6bef87be 2018-09-11 stsp /*
2 6bef87be 2018-09-11 stsp * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
3 6bef87be 2018-09-11 stsp *
4 6bef87be 2018-09-11 stsp * Permission to use, copy, modify, and distribute this software for any
5 6bef87be 2018-09-11 stsp * purpose with or without fee is hereby granted, provided that the above
6 6bef87be 2018-09-11 stsp * copyright notice and this permission notice appear in all copies.
7 6bef87be 2018-09-11 stsp *
8 6bef87be 2018-09-11 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 6bef87be 2018-09-11 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 6bef87be 2018-09-11 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 6bef87be 2018-09-11 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 6bef87be 2018-09-11 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 6bef87be 2018-09-11 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 6bef87be 2018-09-11 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 6bef87be 2018-09-11 stsp */
16 6bef87be 2018-09-11 stsp
17 6bef87be 2018-09-11 stsp #include <sys/time.h>
18 8ab9215c 2021-10-15 thomas #include <sys/resource.h>
19 6bef87be 2018-09-11 stsp
20 6bef87be 2018-09-11 stsp #include <stdio.h>
21 6bef87be 2018-09-11 stsp #include <stdlib.h>
22 a60c9e77 2019-05-22 stsp #include <stdint.h>
23 6bef87be 2018-09-11 stsp #include <string.h>
24 56e0773d 2019-11-28 stsp #include <limits.h>
25 6bef87be 2018-09-11 stsp #include <zlib.h>
26 6bef87be 2018-09-11 stsp
27 6bef87be 2018-09-11 stsp #include "got_error.h"
28 6bef87be 2018-09-11 stsp #include "got_object.h"
29 6bef87be 2018-09-11 stsp
30 6bef87be 2018-09-11 stsp #include "got_lib_delta.h"
31 6bef87be 2018-09-11 stsp #include "got_lib_inflate.h"
32 6bef87be 2018-09-11 stsp #include "got_lib_object.h"
33 f054b67a 2018-11-05 stsp #include "got_lib_object_idset.h"
34 6bef87be 2018-09-11 stsp #include "got_lib_object_cache.h"
35 6bef87be 2018-09-11 stsp
36 a60c9e77 2019-05-22 stsp /*
37 a60c9e77 2019-05-22 stsp * XXX This should be reworked to track cache size and usage in bytes,
38 a60c9e77 2019-05-22 stsp * rather than tracking N elements capped to a maximum element size.
39 a60c9e77 2019-05-22 stsp */
40 9bccfa63 2018-11-05 stsp #define GOT_OBJECT_CACHE_SIZE_OBJ 256
41 9185b863 2018-11-05 stsp #define GOT_OBJECT_CACHE_SIZE_TREE 256
42 9bccfa63 2018-11-05 stsp #define GOT_OBJECT_CACHE_SIZE_COMMIT 64
43 f73df793 2020-01-07 stsp #define GOT_OBJECT_CACHE_SIZE_TAG 2048
44 8ab9215c 2021-10-15 thomas #define GOT_OBJECT_CACHE_SIZE_RAW 64
45 a60c9e77 2019-05-22 stsp #define GOT_OBJECT_CACHE_MAX_ELEM_SIZE 1048576 /* 1 MB */
46 6bef87be 2018-09-11 stsp
47 6bef87be 2018-09-11 stsp const struct got_error *
48 6bef87be 2018-09-11 stsp got_object_cache_init(struct got_object_cache *cache,
49 6bef87be 2018-09-11 stsp enum got_object_cache_type type)
50 6bef87be 2018-09-11 stsp {
51 8ab9215c 2021-10-15 thomas struct rlimit rl;
52 8ab9215c 2021-10-15 thomas
53 dab9d9b6 2018-11-05 stsp memset(cache, 0, sizeof(*cache));
54 dab9d9b6 2018-11-05 stsp
55 f054b67a 2018-11-05 stsp cache->idset = got_object_idset_alloc();
56 f054b67a 2018-11-05 stsp if (cache->idset == NULL)
57 638f9024 2019-05-13 stsp return got_error_from_errno("got_object_idset_alloc");
58 f054b67a 2018-11-05 stsp
59 f054b67a 2018-11-05 stsp cache->type = type;
60 6bef87be 2018-09-11 stsp switch (type) {
61 6bef87be 2018-09-11 stsp case GOT_OBJECT_CACHE_TYPE_OBJ:
62 f054b67a 2018-11-05 stsp cache->size = GOT_OBJECT_CACHE_SIZE_OBJ;
63 6bef87be 2018-09-11 stsp break;
64 6bef87be 2018-09-11 stsp case GOT_OBJECT_CACHE_TYPE_TREE:
65 f054b67a 2018-11-05 stsp cache->size = GOT_OBJECT_CACHE_SIZE_TREE;
66 6bef87be 2018-09-11 stsp break;
67 6bef87be 2018-09-11 stsp case GOT_OBJECT_CACHE_TYPE_COMMIT:
68 f054b67a 2018-11-05 stsp cache->size = GOT_OBJECT_CACHE_SIZE_COMMIT;
69 6bef87be 2018-09-11 stsp break;
70 f4a881ce 2018-11-17 stsp case GOT_OBJECT_CACHE_TYPE_TAG:
71 f4a881ce 2018-11-17 stsp cache->size = GOT_OBJECT_CACHE_SIZE_TAG;
72 f4a881ce 2018-11-17 stsp break;
73 8ab9215c 2021-10-15 thomas case GOT_OBJECT_CACHE_TYPE_RAW:
74 8ab9215c 2021-10-15 thomas if (getrlimit(RLIMIT_NOFILE, &rl) == -1)
75 8ab9215c 2021-10-15 thomas return got_error_from_errno("getrlimit");
76 8ab9215c 2021-10-15 thomas cache->size = GOT_OBJECT_CACHE_SIZE_RAW;
77 8ab9215c 2021-10-15 thomas if (cache->size > rl.rlim_cur / 16)
78 8ab9215c 2021-10-15 thomas cache->size = rl.rlim_cur / 16;
79 8ab9215c 2021-10-15 thomas break;
80 6bef87be 2018-09-11 stsp }
81 6bef87be 2018-09-11 stsp return NULL;
82 a60c9e77 2019-05-22 stsp }
83 a60c9e77 2019-05-22 stsp
84 a60c9e77 2019-05-22 stsp size_t
85 a60c9e77 2019-05-22 stsp get_size_obj(struct got_object *obj)
86 a60c9e77 2019-05-22 stsp {
87 a60c9e77 2019-05-22 stsp size_t size = sizeof(*obj);
88 a60c9e77 2019-05-22 stsp struct got_delta *delta;
89 a60c9e77 2019-05-22 stsp
90 a60c9e77 2019-05-22 stsp if ((obj->flags & GOT_OBJ_FLAG_DELTIFIED) == 0)
91 a60c9e77 2019-05-22 stsp return size;
92 a60c9e77 2019-05-22 stsp
93 dbdddfee 2021-06-23 naddy STAILQ_FOREACH(delta, &obj->deltas.entries, entry) {
94 42c69117 2019-11-10 stsp if (SIZE_MAX - sizeof(*delta) < size)
95 a60c9e77 2019-05-22 stsp return SIZE_MAX;
96 42c69117 2019-11-10 stsp size += sizeof(*delta);
97 a60c9e77 2019-05-22 stsp }
98 a60c9e77 2019-05-22 stsp
99 a60c9e77 2019-05-22 stsp return size;
100 a60c9e77 2019-05-22 stsp }
101 a60c9e77 2019-05-22 stsp
102 a60c9e77 2019-05-22 stsp size_t
103 a60c9e77 2019-05-22 stsp get_size_tree(struct got_tree_object *tree)
104 a60c9e77 2019-05-22 stsp {
105 a60c9e77 2019-05-22 stsp size_t size = sizeof(*tree);
106 a60c9e77 2019-05-22 stsp
107 56e0773d 2019-11-28 stsp size += sizeof(struct got_tree_entry) * tree->nentries;
108 a60c9e77 2019-05-22 stsp return size;
109 a60c9e77 2019-05-22 stsp }
110 a60c9e77 2019-05-22 stsp
111 a60c9e77 2019-05-22 stsp size_t
112 a60c9e77 2019-05-22 stsp get_size_commit(struct got_commit_object *commit)
113 a60c9e77 2019-05-22 stsp {
114 a60c9e77 2019-05-22 stsp size_t size = sizeof(*commit);
115 a60c9e77 2019-05-22 stsp struct got_object_qid *qid;
116 a60c9e77 2019-05-22 stsp
117 a60c9e77 2019-05-22 stsp size += sizeof(*commit->tree_id);
118 a60c9e77 2019-05-22 stsp size += strlen(commit->author);
119 a60c9e77 2019-05-22 stsp size += strlen(commit->committer);
120 a60c9e77 2019-05-22 stsp size += strlen(commit->logmsg);
121 a60c9e77 2019-05-22 stsp
122 dbdddfee 2021-06-23 naddy STAILQ_FOREACH(qid, &commit->parent_ids, entry)
123 a60c9e77 2019-05-22 stsp size += sizeof(*qid) + sizeof(*qid->id);
124 a60c9e77 2019-05-22 stsp
125 a60c9e77 2019-05-22 stsp return size;
126 6bef87be 2018-09-11 stsp }
127 6bef87be 2018-09-11 stsp
128 a60c9e77 2019-05-22 stsp size_t
129 a60c9e77 2019-05-22 stsp get_size_tag(struct got_tag_object *tag)
130 a60c9e77 2019-05-22 stsp {
131 a60c9e77 2019-05-22 stsp size_t size = sizeof(*tag);
132 a60c9e77 2019-05-22 stsp
133 a60c9e77 2019-05-22 stsp size += strlen(tag->tag);
134 a60c9e77 2019-05-22 stsp size += strlen(tag->tagger);
135 a60c9e77 2019-05-22 stsp size += strlen(tag->tagmsg);
136 a60c9e77 2019-05-22 stsp
137 a60c9e77 2019-05-22 stsp return size;
138 a60c9e77 2019-05-22 stsp }
139 a60c9e77 2019-05-22 stsp
140 8ab9215c 2021-10-15 thomas size_t
141 8ab9215c 2021-10-15 thomas get_size_raw(struct got_raw_object *raw)
142 8ab9215c 2021-10-15 thomas {
143 8ab9215c 2021-10-15 thomas return sizeof(*raw);
144 8ab9215c 2021-10-15 thomas }
145 8ab9215c 2021-10-15 thomas
146 6bef87be 2018-09-11 stsp const struct got_error *
147 6bef87be 2018-09-11 stsp got_object_cache_add(struct got_object_cache *cache, struct got_object_id *id, void *item)
148 6bef87be 2018-09-11 stsp {
149 6bef87be 2018-09-11 stsp const struct got_error *err = NULL;
150 6bef87be 2018-09-11 stsp struct got_object_cache_entry *ce;
151 6bef87be 2018-09-11 stsp int nelem;
152 a60c9e77 2019-05-22 stsp size_t size;
153 6bef87be 2018-09-11 stsp
154 a60c9e77 2019-05-22 stsp switch (cache->type) {
155 a60c9e77 2019-05-22 stsp case GOT_OBJECT_CACHE_TYPE_OBJ:
156 a60c9e77 2019-05-22 stsp size = get_size_obj((struct got_object *)item);
157 a60c9e77 2019-05-22 stsp break;
158 a60c9e77 2019-05-22 stsp case GOT_OBJECT_CACHE_TYPE_TREE:
159 a60c9e77 2019-05-22 stsp size = get_size_tree((struct got_tree_object *)item);
160 a60c9e77 2019-05-22 stsp break;
161 a60c9e77 2019-05-22 stsp case GOT_OBJECT_CACHE_TYPE_COMMIT:
162 a60c9e77 2019-05-22 stsp size = get_size_commit((struct got_commit_object *)item);
163 a60c9e77 2019-05-22 stsp break;
164 a60c9e77 2019-05-22 stsp case GOT_OBJECT_CACHE_TYPE_TAG:
165 a60c9e77 2019-05-22 stsp size = get_size_tag((struct got_tag_object *)item);
166 a60c9e77 2019-05-22 stsp break;
167 8ab9215c 2021-10-15 thomas case GOT_OBJECT_CACHE_TYPE_RAW:
168 8ab9215c 2021-10-15 thomas size = get_size_raw((struct got_raw_object *)item);
169 8ab9215c 2021-10-15 thomas break;
170 a0de39f3 2019-08-09 stsp default:
171 a0de39f3 2019-08-09 stsp return got_error(GOT_ERR_OBJ_TYPE);
172 a60c9e77 2019-05-22 stsp }
173 a60c9e77 2019-05-22 stsp
174 01cd7614 2019-05-22 stsp if (size > GOT_OBJECT_CACHE_MAX_ELEM_SIZE) {
175 01cd7614 2019-05-22 stsp #ifdef GOT_OBJ_CACHE_DEBUG
176 01cd7614 2019-05-22 stsp char *id_str;
177 01cd7614 2019-05-22 stsp if (got_object_id_str(&id_str, id) != NULL)
178 01cd7614 2019-05-22 stsp return got_error_from_errno("got_object_id_str");
179 01cd7614 2019-05-22 stsp fprintf(stderr, "%s: not caching ", getprogname());
180 01cd7614 2019-05-22 stsp switch (cache->type) {
181 01cd7614 2019-05-22 stsp case GOT_OBJECT_CACHE_TYPE_OBJ:
182 01cd7614 2019-05-22 stsp fprintf(stderr, "object");
183 01cd7614 2019-05-22 stsp break;
184 01cd7614 2019-05-22 stsp case GOT_OBJECT_CACHE_TYPE_TREE:
185 01cd7614 2019-05-22 stsp fprintf(stderr, "tree");
186 01cd7614 2019-05-22 stsp break;
187 01cd7614 2019-05-22 stsp case GOT_OBJECT_CACHE_TYPE_COMMIT:
188 01cd7614 2019-05-22 stsp fprintf(stderr, "commit");
189 01cd7614 2019-05-22 stsp break;
190 01cd7614 2019-05-22 stsp case GOT_OBJECT_CACHE_TYPE_TAG:
191 01cd7614 2019-05-22 stsp fprintf(stderr, "tag");
192 01cd7614 2019-05-22 stsp break;
193 8ab9215c 2021-10-15 thomas case GOT_OBJECT_CACHE_TYPE_RAW:
194 8ab9215c 2021-10-15 thomas fprintf(stderr, "raw");
195 8ab9215c 2021-10-15 thomas break;
196 01cd7614 2019-05-22 stsp }
197 01cd7614 2019-05-22 stsp fprintf(stderr, " %s (%zd bytes; %zd MB)\n", id_str, size,
198 01cd7614 2019-05-22 stsp size/1024/1024);
199 01cd7614 2019-05-22 stsp free(id_str);
200 01cd7614 2019-05-22 stsp #endif
201 01cd7614 2019-05-22 stsp cache->cache_toolarge++;
202 79c99a64 2019-05-23 stsp return got_error(GOT_ERR_OBJ_TOO_LARGE);
203 01cd7614 2019-05-22 stsp }
204 a60c9e77 2019-05-22 stsp
205 f054b67a 2018-11-05 stsp nelem = got_object_idset_num_elements(cache->idset);
206 6bef87be 2018-09-11 stsp if (nelem >= cache->size) {
207 f054b67a 2018-11-05 stsp err = got_object_idset_remove((void **)&ce,
208 f054b67a 2018-11-05 stsp cache->idset, NULL);
209 6bef87be 2018-09-11 stsp if (err)
210 6bef87be 2018-09-11 stsp return err;
211 6bef87be 2018-09-11 stsp switch (cache->type) {
212 6bef87be 2018-09-11 stsp case GOT_OBJECT_CACHE_TYPE_OBJ:
213 6bef87be 2018-09-11 stsp got_object_close(ce->data.obj);
214 6bef87be 2018-09-11 stsp break;
215 6bef87be 2018-09-11 stsp case GOT_OBJECT_CACHE_TYPE_TREE:
216 6bef87be 2018-09-11 stsp got_object_tree_close(ce->data.tree);
217 6bef87be 2018-09-11 stsp break;
218 6bef87be 2018-09-11 stsp case GOT_OBJECT_CACHE_TYPE_COMMIT:
219 6bef87be 2018-09-11 stsp got_object_commit_close(ce->data.commit);
220 6bef87be 2018-09-11 stsp break;
221 f4a881ce 2018-11-17 stsp case GOT_OBJECT_CACHE_TYPE_TAG:
222 f4a881ce 2018-11-17 stsp got_object_tag_close(ce->data.tag);
223 f4a881ce 2018-11-17 stsp break;
224 8ab9215c 2021-10-15 thomas case GOT_OBJECT_CACHE_TYPE_RAW:
225 8ab9215c 2021-10-15 thomas got_object_raw_close(ce->data.raw);
226 8ab9215c 2021-10-15 thomas break;
227 6bef87be 2018-09-11 stsp }
228 6bef87be 2018-09-11 stsp free(ce);
229 315fa2b2 2018-09-15 stsp cache->cache_evict++;
230 6bef87be 2018-09-11 stsp }
231 6bef87be 2018-09-11 stsp
232 507aef8f 2018-11-05 stsp ce = malloc(sizeof(*ce));
233 6bef87be 2018-09-11 stsp if (ce == NULL)
234 638f9024 2019-05-13 stsp return got_error_from_errno("malloc");
235 6bef87be 2018-09-11 stsp memcpy(&ce->id, id, sizeof(ce->id));
236 6bef87be 2018-09-11 stsp switch (cache->type) {
237 6bef87be 2018-09-11 stsp case GOT_OBJECT_CACHE_TYPE_OBJ:
238 6bef87be 2018-09-11 stsp ce->data.obj = (struct got_object *)item;
239 6bef87be 2018-09-11 stsp break;
240 6bef87be 2018-09-11 stsp case GOT_OBJECT_CACHE_TYPE_TREE:
241 6bef87be 2018-09-11 stsp ce->data.tree = (struct got_tree_object *)item;
242 6bef87be 2018-09-11 stsp break;
243 6bef87be 2018-09-11 stsp case GOT_OBJECT_CACHE_TYPE_COMMIT:
244 6bef87be 2018-09-11 stsp ce->data.commit = (struct got_commit_object *)item;
245 6bef87be 2018-09-11 stsp break;
246 f4a881ce 2018-11-17 stsp case GOT_OBJECT_CACHE_TYPE_TAG:
247 f4a881ce 2018-11-17 stsp ce->data.tag = (struct got_tag_object *)item;
248 f4a881ce 2018-11-17 stsp break;
249 8ab9215c 2021-10-15 thomas case GOT_OBJECT_CACHE_TYPE_RAW:
250 8ab9215c 2021-10-15 thomas ce->data.raw = (struct got_raw_object *)item;
251 8ab9215c 2021-10-15 thomas break;
252 6bef87be 2018-09-11 stsp }
253 6bef87be 2018-09-11 stsp
254 f054b67a 2018-11-05 stsp err = got_object_idset_add(cache->idset, id, ce);
255 79c99a64 2019-05-23 stsp if (err)
256 79c99a64 2019-05-23 stsp free(ce);
257 6bef87be 2018-09-11 stsp return err;
258 6bef87be 2018-09-11 stsp }
259 6bef87be 2018-09-11 stsp
260 6bef87be 2018-09-11 stsp void *
261 6bef87be 2018-09-11 stsp got_object_cache_get(struct got_object_cache *cache, struct got_object_id *id)
262 6bef87be 2018-09-11 stsp {
263 6bef87be 2018-09-11 stsp struct got_object_cache_entry *ce;
264 6bef87be 2018-09-11 stsp
265 221e79cd 2018-09-16 stsp cache->cache_searches++;
266 f054b67a 2018-11-05 stsp ce = got_object_idset_get(cache->idset, id);
267 6bef87be 2018-09-11 stsp if (ce) {
268 6bef87be 2018-09-11 stsp cache->cache_hit++;
269 6bef87be 2018-09-11 stsp switch (cache->type) {
270 6bef87be 2018-09-11 stsp case GOT_OBJECT_CACHE_TYPE_OBJ:
271 6bef87be 2018-09-11 stsp return ce->data.obj;
272 6bef87be 2018-09-11 stsp case GOT_OBJECT_CACHE_TYPE_TREE:
273 6bef87be 2018-09-11 stsp return ce->data.tree;
274 6bef87be 2018-09-11 stsp case GOT_OBJECT_CACHE_TYPE_COMMIT:
275 6bef87be 2018-09-11 stsp return ce->data.commit;
276 f4a881ce 2018-11-17 stsp case GOT_OBJECT_CACHE_TYPE_TAG:
277 f4a881ce 2018-11-17 stsp return ce->data.tag;
278 8ab9215c 2021-10-15 thomas case GOT_OBJECT_CACHE_TYPE_RAW:
279 8ab9215c 2021-10-15 thomas return ce->data.raw;
280 6bef87be 2018-09-11 stsp }
281 6bef87be 2018-09-11 stsp }
282 6bef87be 2018-09-11 stsp
283 6bef87be 2018-09-11 stsp cache->cache_miss++;
284 6bef87be 2018-09-11 stsp return NULL;
285 6bef87be 2018-09-11 stsp }
286 6bef87be 2018-09-11 stsp
287 f4081577 2018-09-15 stsp #ifdef GOT_OBJ_CACHE_DEBUG
288 6bef87be 2018-09-11 stsp static void
289 6bef87be 2018-09-11 stsp print_cache_stats(struct got_object_cache *cache, const char *name)
290 6bef87be 2018-09-11 stsp {
291 221e79cd 2018-09-16 stsp fprintf(stderr, "%s: %s cache: %d elements, %d searches, %d hits, "
292 01cd7614 2019-05-22 stsp "%d missed, %d evicted, %d too large\n", getprogname(), name,
293 f054b67a 2018-11-05 stsp got_object_idset_num_elements(cache->idset),
294 221e79cd 2018-09-16 stsp cache->cache_searches, cache->cache_hit,
295 01cd7614 2019-05-22 stsp cache->cache_miss, cache->cache_evict, cache->cache_toolarge);
296 6bef87be 2018-09-11 stsp }
297 6bef87be 2018-09-11 stsp
298 cb103d04 2018-11-07 stsp const struct got_error *
299 cb103d04 2018-11-07 stsp check_refcount(struct got_object_id *id, void *data, void *arg)
300 6bef87be 2018-09-11 stsp {
301 6bef87be 2018-09-11 stsp struct got_object_cache *cache = arg;
302 6bef87be 2018-09-11 stsp struct got_object_cache_entry *ce = data;
303 6bef87be 2018-09-11 stsp struct got_object *obj;
304 6bef87be 2018-09-11 stsp struct got_tree_object *tree;
305 6bef87be 2018-09-11 stsp struct got_commit_object *commit;
306 f4a881ce 2018-11-17 stsp struct got_tag_object *tag;
307 8ab9215c 2021-10-15 thomas struct got_raw_object *raw;
308 6bef87be 2018-09-11 stsp char *id_str;
309 6bef87be 2018-09-11 stsp
310 6bef87be 2018-09-11 stsp if (got_object_id_str(&id_str, id) != NULL)
311 cb103d04 2018-11-07 stsp return NULL;
312 6bef87be 2018-09-11 stsp
313 6bef87be 2018-09-11 stsp switch (cache->type) {
314 6bef87be 2018-09-11 stsp case GOT_OBJECT_CACHE_TYPE_OBJ:
315 6bef87be 2018-09-11 stsp obj = ce->data.obj;
316 6bef87be 2018-09-11 stsp if (obj->refcnt == 1)
317 6bef87be 2018-09-11 stsp break;
318 6bef87be 2018-09-11 stsp fprintf(stderr, "object %s has %d unclaimed references\n",
319 6bef87be 2018-09-11 stsp id_str, obj->refcnt - 1);
320 6bef87be 2018-09-11 stsp break;
321 6bef87be 2018-09-11 stsp case GOT_OBJECT_CACHE_TYPE_TREE:
322 6bef87be 2018-09-11 stsp tree = ce->data.tree;
323 6bef87be 2018-09-11 stsp if (tree->refcnt == 1)
324 6bef87be 2018-09-11 stsp break;
325 6bef87be 2018-09-11 stsp fprintf(stderr, "tree %s has %d unclaimed references\n",
326 6bef87be 2018-09-11 stsp id_str, tree->refcnt - 1);
327 6bef87be 2018-09-11 stsp break;
328 6bef87be 2018-09-11 stsp case GOT_OBJECT_CACHE_TYPE_COMMIT:
329 6bef87be 2018-09-11 stsp commit = ce->data.commit;
330 6bef87be 2018-09-11 stsp if (commit->refcnt == 1)
331 6bef87be 2018-09-11 stsp break;
332 6bef87be 2018-09-11 stsp fprintf(stderr, "commit %s has %d unclaimed references\n",
333 414611d9 2018-09-19 stsp id_str, commit->refcnt - 1);
334 6bef87be 2018-09-11 stsp break;
335 f4a881ce 2018-11-17 stsp case GOT_OBJECT_CACHE_TYPE_TAG:
336 f4a881ce 2018-11-17 stsp tag = ce->data.tag;
337 f4a881ce 2018-11-17 stsp if (tag->refcnt == 1)
338 f4a881ce 2018-11-17 stsp break;
339 f4a881ce 2018-11-17 stsp fprintf(stderr, "tag %s has %d unclaimed references\n",
340 f4a881ce 2018-11-17 stsp id_str, tag->refcnt - 1);
341 f4a881ce 2018-11-17 stsp break;
342 8ab9215c 2021-10-15 thomas case GOT_OBJECT_CACHE_TYPE_RAW:
343 8ab9215c 2021-10-15 thomas raw = ce->data.raw;
344 8ab9215c 2021-10-15 thomas if (raw->refcnt == 1)
345 8ab9215c 2021-10-15 thomas break;
346 8ab9215c 2021-10-15 thomas fprintf(stderr, "raw %s has %d unclaimed references\n",
347 8ab9215c 2021-10-15 thomas id_str, raw->refcnt - 1);
348 8ab9215c 2021-10-15 thomas break;
349 6bef87be 2018-09-11 stsp }
350 6bef87be 2018-09-11 stsp free(id_str);
351 cb103d04 2018-11-07 stsp return NULL;
352 6bef87be 2018-09-11 stsp }
353 6bef87be 2018-09-11 stsp #endif
354 6bef87be 2018-09-11 stsp
355 6bef87be 2018-09-11 stsp void
356 6bef87be 2018-09-11 stsp got_object_cache_close(struct got_object_cache *cache)
357 6bef87be 2018-09-11 stsp {
358 f4081577 2018-09-15 stsp #ifdef GOT_OBJ_CACHE_DEBUG
359 6bef87be 2018-09-11 stsp switch (cache->type) {
360 6bef87be 2018-09-11 stsp case GOT_OBJECT_CACHE_TYPE_OBJ:
361 6bef87be 2018-09-11 stsp print_cache_stats(cache, "object");
362 6bef87be 2018-09-11 stsp break;
363 6bef87be 2018-09-11 stsp case GOT_OBJECT_CACHE_TYPE_TREE:
364 6bef87be 2018-09-11 stsp print_cache_stats(cache, "tree");
365 6bef87be 2018-09-11 stsp break;
366 6bef87be 2018-09-11 stsp case GOT_OBJECT_CACHE_TYPE_COMMIT:
367 6bef87be 2018-09-11 stsp print_cache_stats(cache, "commit");
368 6bef87be 2018-09-11 stsp break;
369 2ee32b23 2019-05-15 stsp case GOT_OBJECT_CACHE_TYPE_TAG:
370 2ee32b23 2019-05-15 stsp print_cache_stats(cache, "tag");
371 2ee32b23 2019-05-15 stsp break;
372 8ab9215c 2021-10-15 thomas case GOT_OBJECT_CACHE_TYPE_RAW:
373 8ab9215c 2021-10-15 thomas print_cache_stats(cache, "raw");
374 8ab9215c 2021-10-15 thomas break;
375 6bef87be 2018-09-11 stsp }
376 6bef87be 2018-09-11 stsp
377 f054b67a 2018-11-05 stsp got_object_idset_for_each(cache->idset, check_refcount, cache);
378 6bef87be 2018-09-11 stsp #endif
379 6bef87be 2018-09-11 stsp
380 f054b67a 2018-11-05 stsp if (cache->idset) {
381 f054b67a 2018-11-05 stsp got_object_idset_free(cache->idset);
382 f054b67a 2018-11-05 stsp cache->idset = NULL;
383 6bef87be 2018-09-11 stsp }
384 6bef87be 2018-09-11 stsp cache->size = 0;
385 6bef87be 2018-09-11 stsp }