Lines Matching refs:ckp
101 fmd_ckpt_create(fmd_ckpt_t *ckp, fmd_module_t *mp) in fmd_ckpt_create() argument
107 bzero(ckp, sizeof (fmd_ckpt_t)); in fmd_ckpt_create()
108 ckp->ckp_mp = mp; in fmd_ckpt_create()
110 ckp->ckp_size = sizeof (fcf_hdr_t); in fmd_ckpt_create()
111 ckp->ckp_strn = 1; /* for \0 */ in fmd_ckpt_create()
113 (void) snprintf(ckp->ckp_src, PATH_MAX, "%s/%s+", dir, name); in fmd_ckpt_create()
114 (void) snprintf(ckp->ckp_dst, PATH_MAX, "%s/%s", dir, name); in fmd_ckpt_create()
116 (void) unlink(ckp->ckp_src); in fmd_ckpt_create()
118 ckp->ckp_fd = open64(ckp->ckp_src, O_WRONLY | O_CREAT | O_EXCL, mode); in fmd_ckpt_create()
120 return (ckp->ckp_fd); in fmd_ckpt_create()
125 fmd_ckpt_inval(fmd_ckpt_t *ckp, const char *format, ...) in fmd_ckpt_inval() argument
133 fmd_free(ckp->ckp_buf, ckp->ckp_size); in fmd_ckpt_inval()
138 fmd_ckpt_open(fmd_ckpt_t *ckp, fmd_module_t *mp) in fmd_ckpt_open() argument
145 bzero(ckp, sizeof (fmd_ckpt_t)); in fmd_ckpt_open()
146 ckp->ckp_mp = mp; in fmd_ckpt_open()
148 (void) snprintf(ckp->ckp_src, PATH_MAX, "%s/%s", in fmd_ckpt_open()
151 if ((ckp->ckp_fd = open(ckp->ckp_src, O_RDONLY)) == -1) in fmd_ckpt_open()
154 if (fstat64(ckp->ckp_fd, &st) == -1) { in fmd_ckpt_open()
156 (void) close(ckp->ckp_fd); in fmd_ckpt_open()
160 ckp->ckp_buf = fmd_alloc(st.st_size, FMD_SLEEP); in fmd_ckpt_open()
161 ckp->ckp_hdr = (void *)ckp->ckp_buf; in fmd_ckpt_open()
162 ckp->ckp_size = read(ckp->ckp_fd, ckp->ckp_buf, st.st_size); in fmd_ckpt_open()
164 if (ckp->ckp_size != st.st_size || ckp->ckp_size < sizeof (fcf_hdr_t) || in fmd_ckpt_open()
165 ckp->ckp_size != ckp->ckp_hdr->fcfh_filesz) { in fmd_ckpt_open()
166 err = ckp->ckp_size == (size_t)-1L ? errno : EFMD_CKPT_SHORT; in fmd_ckpt_open()
167 fmd_free(ckp->ckp_buf, st.st_size); in fmd_ckpt_open()
168 (void) close(ckp->ckp_fd); in fmd_ckpt_open()
172 (void) close(ckp->ckp_fd); in fmd_ckpt_open()
173 ckp->ckp_fd = -1; in fmd_ckpt_open()
181 if (bcmp(&ckp->ckp_hdr->fcfh_ident[FCF_ID_MAG0], in fmd_ckpt_open()
183 return (fmd_ckpt_inval(ckp, "bad checkpoint magic string\n")); in fmd_ckpt_open()
185 if (ckp->ckp_hdr->fcfh_ident[FCF_ID_MODEL] != FCF_MODEL_NATIVE) in fmd_ckpt_open()
186 return (fmd_ckpt_inval(ckp, "bad checkpoint data model\n")); in fmd_ckpt_open()
188 if (ckp->ckp_hdr->fcfh_ident[FCF_ID_ENCODING] != FCF_ENCODE_NATIVE) in fmd_ckpt_open()
189 return (fmd_ckpt_inval(ckp, "bad checkpoint data encoding\n")); in fmd_ckpt_open()
191 if (ckp->ckp_hdr->fcfh_ident[FCF_ID_VERSION] != FCF_VERSION_1) { in fmd_ckpt_open()
192 return (fmd_ckpt_inval(ckp, "bad checkpoint version %u\n", in fmd_ckpt_open()
193 ckp->ckp_hdr->fcfh_ident[FCF_ID_VERSION])); in fmd_ckpt_open()
197 if (ckp->ckp_hdr->fcfh_ident[i] != 0) { in fmd_ckpt_open()
198 return (fmd_ckpt_inval(ckp, in fmd_ckpt_open()
203 if (ckp->ckp_hdr->fcfh_flags & ~FCF_FL_VALID) in fmd_ckpt_open()
204 return (fmd_ckpt_inval(ckp, "bad checkpoint flags\n")); in fmd_ckpt_open()
206 if (ckp->ckp_hdr->fcfh_pad != 0) in fmd_ckpt_open()
207 return (fmd_ckpt_inval(ckp, "reserved field in use\n")); in fmd_ckpt_open()
209 if (ckp->ckp_hdr->fcfh_hdrsize < sizeof (fcf_hdr_t) || in fmd_ckpt_open()
210 ckp->ckp_hdr->fcfh_secsize < sizeof (fcf_sec_t)) { in fmd_ckpt_open()
211 return (fmd_ckpt_inval(ckp, in fmd_ckpt_open()
215 seclen = (uint64_t)ckp->ckp_hdr->fcfh_secnum * in fmd_ckpt_open()
216 (uint64_t)ckp->ckp_hdr->fcfh_secsize; in fmd_ckpt_open()
218 if (ckp->ckp_hdr->fcfh_secoff > ckp->ckp_size || in fmd_ckpt_open()
219 seclen > ckp->ckp_size || in fmd_ckpt_open()
220 ckp->ckp_hdr->fcfh_secoff + seclen > ckp->ckp_size || in fmd_ckpt_open()
221 ckp->ckp_hdr->fcfh_secoff + seclen < ckp->ckp_hdr->fcfh_secoff) in fmd_ckpt_open()
222 return (fmd_ckpt_inval(ckp, "truncated section headers\n")); in fmd_ckpt_open()
224 if (!IS_P2ALIGNED(ckp->ckp_hdr->fcfh_secoff, sizeof (uint64_t)) || in fmd_ckpt_open()
225 !IS_P2ALIGNED(ckp->ckp_hdr->fcfh_secsize, sizeof (uint64_t))) in fmd_ckpt_open()
226 return (fmd_ckpt_inval(ckp, "misaligned section headers\n")); in fmd_ckpt_open()
233 ckp->ckp_secp = (void *)(ckp->ckp_buf + ckp->ckp_hdr->fcfh_secoff); in fmd_ckpt_open()
234 ckp->ckp_secs = ckp->ckp_hdr->fcfh_secnum; in fmd_ckpt_open()
236 for (i = 0; i < ckp->ckp_secs; i++) { in fmd_ckpt_open()
237 fcf_sec_t *sp = (void *)(ckp->ckp_buf + in fmd_ckpt_open()
238 ckp->ckp_hdr->fcfh_secoff + ckp->ckp_hdr->fcfh_secsize * i); in fmd_ckpt_open()
243 return (fmd_ckpt_inval(ckp, "section %u has invalid " in fmd_ckpt_open()
248 return (fmd_ckpt_inval(ckp, "section %u has invalid " in fmd_ckpt_open()
253 return (fmd_ckpt_inval(ckp, "section %u is not properly" in fmd_ckpt_open()
259 return (fmd_ckpt_inval(ckp, "section %u has misaligned " in fmd_ckpt_open()
263 if (sp->fcfs_offset > ckp->ckp_size || in fmd_ckpt_open()
264 sp->fcfs_size > ckp->ckp_size || in fmd_ckpt_open()
265 sp->fcfs_offset + sp->fcfs_size > ckp->ckp_size || in fmd_ckpt_open()
267 return (fmd_ckpt_inval(ckp, "section %u has corrupt " in fmd_ckpt_open()
273 return (fmd_ckpt_inval(ckp, "section %u has unknown " in fmd_ckpt_open()
278 return (fmd_ckpt_inval(ckp, "section %u has align %u " in fmd_ckpt_open()
284 return (fmd_ckpt_inval(ckp, "section %u has short " in fmd_ckpt_open()
290 if (ckp->ckp_strs != NULL) { in fmd_ckpt_open()
291 return (fmd_ckpt_inval(ckp, "multiple string " in fmd_ckpt_open()
295 ckp->ckp_strs = (char *)ckp->ckp_buf + sp->fcfs_offset; in fmd_ckpt_open()
296 ckp->ckp_strn = sp->fcfs_size; in fmd_ckpt_open()
298 if (ckp->ckp_strs[ckp->ckp_strn - 1] != '\0') { in fmd_ckpt_open()
299 return (fmd_ckpt_inval(ckp, "string table %u " in fmd_ckpt_open()
305 if (ckp->ckp_modp != NULL) { in fmd_ckpt_open()
306 return (fmd_ckpt_inval(ckp, "multiple module " in fmd_ckpt_open()
309 ckp->ckp_modp = sp; in fmd_ckpt_open()
318 if (ckp->ckp_secs == 0 || ckp->ckp_secp->fcfs_type != FCF_SECT_NONE || in fmd_ckpt_open()
319 ckp->ckp_secp->fcfs_entsize != 0 || ckp->ckp_secp->fcfs_size != 0) { in fmd_ckpt_open()
320 return (fmd_ckpt_inval(ckp, "section 0 is not of the " in fmd_ckpt_open()
324 if (ckp->ckp_modp == NULL) { in fmd_ckpt_open()
325 return (fmd_ckpt_inval(ckp, in fmd_ckpt_open()
333 fmd_ckpt_destroy(fmd_ckpt_t *ckp) in fmd_ckpt_destroy() argument
335 if (ckp->ckp_buf != NULL) in fmd_ckpt_destroy()
336 fmd_free(ckp->ckp_buf, ckp->ckp_size); in fmd_ckpt_destroy()
337 if (ckp->ckp_fd >= 0) in fmd_ckpt_destroy()
338 (void) close(ckp->ckp_fd); in fmd_ckpt_destroy()
350 fmd_ckpt_error(fmd_ckpt_t *ckp, int err, const char *format, ...) in fmd_ckpt_error() argument
352 fmd_module_t *mp = ckp->ckp_mp; in fmd_ckpt_error()
362 fmd_ckpt_destroy(ckp); in fmd_ckpt_error()
367 fmd_ckpt_section(fmd_ckpt_t *ckp, const void *data, uint_t type, uint64_t size) in fmd_ckpt_section() argument
374 ckp->ckp_ptr = (uchar_t *) in fmd_ckpt_section()
375 P2ROUNDUP((uintptr_t)ckp->ckp_ptr, dp->secd_align); in fmd_ckpt_section()
377 ckp->ckp_secp->fcfs_type = type; in fmd_ckpt_section()
378 ckp->ckp_secp->fcfs_align = dp->secd_align; in fmd_ckpt_section()
379 ckp->ckp_secp->fcfs_flags = 0; in fmd_ckpt_section()
380 ckp->ckp_secp->fcfs_entsize = dp->secd_entsize; in fmd_ckpt_section()
381 ckp->ckp_secp->fcfs_offset = (size_t)(ckp->ckp_ptr - ckp->ckp_buf); in fmd_ckpt_section()
382 ckp->ckp_secp->fcfs_size = size; in fmd_ckpt_section()
389 bcopy(data, ckp->ckp_ptr, size); in fmd_ckpt_section()
390 ckp->ckp_ptr += size; in fmd_ckpt_section()
393 ckp->ckp_secp++; in fmd_ckpt_section()
394 return (ckp->ckp_secs++); in fmd_ckpt_section()
398 fmd_ckpt_string(fmd_ckpt_t *ckp, const char *s) in fmd_ckpt_string() argument
400 fcf_stridx_t idx = (fcf_stridx_t)(ckp->ckp_strp - ckp->ckp_strs); in fmd_ckpt_string()
402 (void) strcpy(ckp->ckp_strp, s); in fmd_ckpt_string()
403 ckp->ckp_strp += strlen(s) + 1; in fmd_ckpt_string()
409 fmd_ckpt_alloc(fmd_ckpt_t *ckp, uint64_t gen) in fmd_ckpt_alloc() argument
419 ckp->ckp_secs += 2; /* for FCF_SECT_NONE and FCF_SECT_STRTAB */ in fmd_ckpt_alloc()
420 ckp->ckp_size += sizeof (fcf_sec_t) * ckp->ckp_secs; in fmd_ckpt_alloc()
421 ckp->ckp_size += ckp->ckp_strn; in fmd_ckpt_alloc()
423 TRACE((FMD_DBG_CKPT, "alloc fcf buf size %u", ckp->ckp_size)); in fmd_ckpt_alloc()
424 ckp->ckp_buf = fmd_zalloc(ckp->ckp_size, FMD_NOSLEEP); in fmd_ckpt_alloc()
426 if (ckp->ckp_buf == NULL) in fmd_ckpt_alloc()
429 ckp->ckp_hdr = (void *)ckp->ckp_buf; in fmd_ckpt_alloc()
431 ckp->ckp_hdr->fcfh_ident[FCF_ID_MAG0] = FCF_MAG_MAG0; in fmd_ckpt_alloc()
432 ckp->ckp_hdr->fcfh_ident[FCF_ID_MAG1] = FCF_MAG_MAG1; in fmd_ckpt_alloc()
433 ckp->ckp_hdr->fcfh_ident[FCF_ID_MAG2] = FCF_MAG_MAG2; in fmd_ckpt_alloc()
434 ckp->ckp_hdr->fcfh_ident[FCF_ID_MAG3] = FCF_MAG_MAG3; in fmd_ckpt_alloc()
435 ckp->ckp_hdr->fcfh_ident[FCF_ID_MODEL] = FCF_MODEL_NATIVE; in fmd_ckpt_alloc()
436 ckp->ckp_hdr->fcfh_ident[FCF_ID_ENCODING] = FCF_ENCODE_NATIVE; in fmd_ckpt_alloc()
437 ckp->ckp_hdr->fcfh_ident[FCF_ID_VERSION] = FCF_VERSION; in fmd_ckpt_alloc()
439 ckp->ckp_hdr->fcfh_hdrsize = sizeof (fcf_hdr_t); in fmd_ckpt_alloc()
440 ckp->ckp_hdr->fcfh_secsize = sizeof (fcf_sec_t); in fmd_ckpt_alloc()
441 ckp->ckp_hdr->fcfh_secnum = ckp->ckp_secs; in fmd_ckpt_alloc()
442 ckp->ckp_hdr->fcfh_secoff = sizeof (fcf_hdr_t); in fmd_ckpt_alloc()
443 ckp->ckp_hdr->fcfh_filesz = ckp->ckp_size; in fmd_ckpt_alloc()
444 ckp->ckp_hdr->fcfh_cgen = gen; in fmd_ckpt_alloc()
446 ckp->ckp_secs = 0; /* reset section counter for second pass */ in fmd_ckpt_alloc()
447 ckp->ckp_secp = (void *)(ckp->ckp_buf + sizeof (fcf_hdr_t)); in fmd_ckpt_alloc()
448 ckp->ckp_strs = (char *)ckp->ckp_buf + ckp->ckp_size - ckp->ckp_strn; in fmd_ckpt_alloc()
449 ckp->ckp_strp = ckp->ckp_strs + 1; /* use first byte as \0 */ in fmd_ckpt_alloc()
450 ckp->ckp_ptr = (uchar_t *)(ckp->ckp_secp + ckp->ckp_hdr->fcfh_secnum); in fmd_ckpt_alloc()
452 (void) fmd_ckpt_section(ckp, NULL, FCF_SECT_NONE, 0); in fmd_ckpt_alloc()
457 fmd_ckpt_commit(fmd_ckpt_t *ckp) in fmd_ckpt_commit() argument
459 fcf_sec_t *secbase = (void *)(ckp->ckp_buf + sizeof (fcf_hdr_t)); in fmd_ckpt_commit()
460 size_t stroff = ckp->ckp_size - ckp->ckp_strn; in fmd_ckpt_commit()
468 ASSERT((size_t)(ckp->ckp_ptr - ckp->ckp_buf) == stroff); in fmd_ckpt_commit()
469 (void) fmd_ckpt_section(ckp, NULL, FCF_SECT_STRTAB, ckp->ckp_strn); in fmd_ckpt_commit()
470 ckp->ckp_ptr += ckp->ckp_strn; /* string table is already filled in */ in fmd_ckpt_commit()
472 ASSERT(ckp->ckp_secs == ckp->ckp_hdr->fcfh_secnum); in fmd_ckpt_commit()
473 ASSERT(ckp->ckp_secp == secbase + ckp->ckp_hdr->fcfh_secnum); in fmd_ckpt_commit()
474 ASSERT(ckp->ckp_ptr == ckp->ckp_buf + ckp->ckp_hdr->fcfh_filesz); in fmd_ckpt_commit()
476 if (write(ckp->ckp_fd, ckp->ckp_buf, ckp->ckp_size) != ckp->ckp_size || in fmd_ckpt_commit()
477 fsync(ckp->ckp_fd) != 0 || close(ckp->ckp_fd) != 0) in fmd_ckpt_commit()
480 ckp->ckp_fd = -1; /* fd is now closed */ in fmd_ckpt_commit()
481 return (rename(ckp->ckp_src, ckp->ckp_dst) != 0); in fmd_ckpt_commit()
485 fmd_ckpt_resv(fmd_ckpt_t *ckp, size_t size, size_t align) in fmd_ckpt_resv() argument
488 ckp->ckp_size = P2ROUNDUP(ckp->ckp_size, align) + size; in fmd_ckpt_resv()
489 ckp->ckp_secs++; in fmd_ckpt_resv()
494 fmd_ckpt_resv_buf(fmd_buf_t *bp, fmd_ckpt_t *ckp) in fmd_ckpt_resv_buf() argument
496 ckp->ckp_size = P2ROUNDUP(ckp->ckp_size, _MAX_ALIGNMENT) + bp->buf_size; in fmd_ckpt_resv_buf()
497 ckp->ckp_strn += strlen(bp->buf_name) + 1; in fmd_ckpt_resv_buf()
498 ckp->ckp_secs++; in fmd_ckpt_resv_buf()
502 fmd_ckpt_save_buf(fmd_buf_t *bp, fmd_ckpt_t *ckp) in fmd_ckpt_save_buf() argument
504 fcf_buf_t *fcfb = ckp->ckp_arg; in fmd_ckpt_save_buf()
506 fcfb->fcfb_name = fmd_ckpt_string(ckp, bp->buf_name); in fmd_ckpt_save_buf()
507 fcfb->fcfb_data = fmd_ckpt_section(ckp, in fmd_ckpt_save_buf()
510 ckp->ckp_arg = fcfb + 1; in fmd_ckpt_save_buf()
514 fmd_ckpt_save_event(fmd_ckpt_t *ckp, fmd_event_t *e) in fmd_ckpt_save_event() argument
516 fcf_event_t *fcfe = (void *)ckp->ckp_ptr; in fmd_ckpt_save_event()
527 ckp->ckp_ptr += sizeof (fcf_event_t); in fmd_ckpt_save_event()
531 fmd_ckpt_save_nvlist(fmd_ckpt_t *ckp, nvlist_t *nvl) in fmd_ckpt_save_nvlist() argument
533 fcf_nvl_t *fcfn = (void *)ckp->ckp_ptr; in fmd_ckpt_save_nvlist()
534 char *nvbuf = (char *)ckp->ckp_ptr + sizeof (fcf_nvl_t); in fmd_ckpt_save_nvlist()
541 ckp->ckp_ptr += sizeof (fcf_nvl_t) + nvsize; in fmd_ckpt_save_nvlist()
543 ckp->ckp_ptr = (uchar_t *) in fmd_ckpt_save_nvlist()
544 P2ROUNDUP((uintptr_t)ckp->ckp_ptr, sizeof (uint64_t)); in fmd_ckpt_save_nvlist()
548 fmd_ckpt_resv_serd(fmd_serd_eng_t *sgp, fmd_ckpt_t *ckp) in fmd_ckpt_resv_serd() argument
550 fmd_ckpt_resv(ckp, in fmd_ckpt_resv_serd()
553 ckp->ckp_strn += strlen(sgp->sg_name) + 1; in fmd_ckpt_resv_serd()
557 fmd_ckpt_save_serd(fmd_serd_eng_t *sgp, fmd_ckpt_t *ckp) in fmd_ckpt_save_serd() argument
559 fcf_serd_t *fcfd = ckp->ckp_arg; in fmd_ckpt_save_serd()
564 evsec = fmd_ckpt_section(ckp, NULL, FCF_SECT_EVENTS, in fmd_ckpt_save_serd()
569 fmd_ckpt_save_event(ckp, sep->se_event); in fmd_ckpt_save_serd()
572 fcfd->fcfd_name = fmd_ckpt_string(ckp, sgp->sg_name); in fmd_ckpt_save_serd()
578 ckp->ckp_arg = fcfd + 1; in fmd_ckpt_save_serd()
582 fmd_ckpt_resv_case(fmd_ckpt_t *ckp, fmd_case_t *cp) in fmd_ckpt_resv_case() argument
592 fmd_buf_hash_apply(&cip->ci_bufs, (fmd_buf_f *)fmd_ckpt_resv_buf, ckp); in fmd_ckpt_resv_case()
593 fmd_ckpt_resv(ckp, sizeof (fcf_buf_t) * n, sizeof (uint32_t)); in fmd_ckpt_resv_case()
596 fmd_ckpt_resv(ckp, sizeof (fcf_event_t), sizeof (uint64_t)); in fmd_ckpt_resv_case()
598 fmd_ckpt_resv(ckp, in fmd_ckpt_resv_case()
602 ckp->ckp_size = P2ROUNDUP(ckp->ckp_size, sizeof (uint64_t)); in fmd_ckpt_resv_case()
614 fmd_ckpt_resv(ckp, cip->ci_nvsz, sizeof (uint64_t)); in fmd_ckpt_resv_case()
615 fmd_ckpt_resv(ckp, sizeof (fcf_case_t), sizeof (uint32_t)); in fmd_ckpt_resv_case()
616 ckp->ckp_strn += strlen(cip->ci_uuid) + 1; in fmd_ckpt_resv_case()
620 fmd_ckpt_save_case(fmd_ckpt_t *ckp, fmd_case_t *cp) in fmd_ckpt_save_case() argument
639 fcf_buf_t *bufs = ckp->ckp_arg = fmd_alloc(size, FMD_SLEEP); in fmd_ckpt_save_case()
642 (fmd_buf_f *)fmd_ckpt_save_buf, ckp); in fmd_ckpt_save_case()
644 bufsec = fmd_ckpt_section(ckp, bufs, FCF_SECT_BUFS, size); in fmd_ckpt_save_case()
649 prsec = fmd_ckpt_section(ckp, NULL, FCF_SECT_EVENTS, in fmd_ckpt_save_case()
652 fmd_ckpt_save_event(ckp, cip->ci_principal); in fmd_ckpt_save_case()
656 evsec = fmd_ckpt_section(ckp, NULL, FCF_SECT_EVENTS, in fmd_ckpt_save_case()
660 fmd_ckpt_save_event(ckp, cit->cit_event); in fmd_ckpt_save_case()
664 nvsec = fmd_ckpt_section(ckp, NULL, in fmd_ckpt_save_case()
668 fmd_ckpt_save_nvlist(ckp, cis->cis_nvl); in fmd_ckpt_save_case()
671 fcfc.fcfc_uuid = fmd_ckpt_string(ckp, cip->ci_uuid); in fmd_ckpt_save_case()
692 (void) fmd_ckpt_section(ckp, &fcfc, FCF_SECT_CASE, sizeof (fcf_case_t)); in fmd_ckpt_save_case()
696 fmd_ckpt_resv_module(fmd_ckpt_t *ckp, fmd_module_t *mp) in fmd_ckpt_resv_module() argument
702 fmd_ckpt_resv_case(ckp, cp); in fmd_ckpt_resv_module()
706 (fmd_serd_eng_f *)fmd_ckpt_resv_serd, ckp); in fmd_ckpt_resv_module()
707 fmd_ckpt_resv(ckp, sizeof (fcf_serd_t) * n, sizeof (uint64_t)); in fmd_ckpt_resv_module()
710 fmd_buf_hash_apply(&mp->mod_bufs, (fmd_buf_f *)fmd_ckpt_resv_buf, ckp); in fmd_ckpt_resv_module()
711 fmd_ckpt_resv(ckp, sizeof (fcf_buf_t) * n, sizeof (uint32_t)); in fmd_ckpt_resv_module()
713 fmd_ckpt_resv(ckp, sizeof (fcf_module_t), sizeof (uint32_t)); in fmd_ckpt_resv_module()
714 ckp->ckp_strn += strlen(mp->mod_name) + 1; in fmd_ckpt_resv_module()
715 ckp->ckp_strn += strlen(mp->mod_path) + 1; in fmd_ckpt_resv_module()
716 ckp->ckp_strn += strlen(mp->mod_info->fmdi_desc) + 1; in fmd_ckpt_resv_module()
717 ckp->ckp_strn += strlen(mp->mod_info->fmdi_vers) + 1; in fmd_ckpt_resv_module()
721 fmd_ckpt_save_module(fmd_ckpt_t *ckp, fmd_module_t *mp) in fmd_ckpt_save_module() argument
729 fmd_ckpt_save_case(ckp, cp); in fmd_ckpt_save_module()
733 fcf_serd_t *serds = ckp->ckp_arg = fmd_alloc(size, FMD_SLEEP); in fmd_ckpt_save_module()
736 (fmd_serd_eng_f *)fmd_ckpt_save_serd, ckp); in fmd_ckpt_save_module()
738 (void) fmd_ckpt_section(ckp, serds, FCF_SECT_SERD, size); in fmd_ckpt_save_module()
744 fcf_buf_t *bufs = ckp->ckp_arg = fmd_alloc(size, FMD_SLEEP); in fmd_ckpt_save_module()
747 (fmd_buf_f *)fmd_ckpt_save_buf, ckp); in fmd_ckpt_save_module()
749 bufsec = fmd_ckpt_section(ckp, bufs, FCF_SECT_BUFS, size); in fmd_ckpt_save_module()
753 fcfm.fcfm_name = fmd_ckpt_string(ckp, mp->mod_name); in fmd_ckpt_save_module()
754 fcfm.fcfm_path = fmd_ckpt_string(ckp, mp->mod_path); in fmd_ckpt_save_module()
755 fcfm.fcfm_desc = fmd_ckpt_string(ckp, mp->mod_info->fmdi_desc); in fmd_ckpt_save_module()
756 fcfm.fcfm_vers = fmd_ckpt_string(ckp, mp->mod_info->fmdi_vers); in fmd_ckpt_save_module()
759 (void) fmd_ckpt_section(ckp, &fcfm, in fmd_ckpt_save_module()
771 fmd_ckpt_t ckp; in fmd_ckpt_save() local
814 if (fmd_ckpt_create(&ckp, mp) == -1) { in fmd_ckpt_save()
815 fmd_error(EFMD_CKPT_CREATE, "failed to create %s", ckp.ckp_src); in fmd_ckpt_save()
819 fmd_ckpt_resv_module(&ckp, mp); in fmd_ckpt_save()
821 if (fmd_ckpt_alloc(&ckp, mp->mod_gen + 1) != 0) { in fmd_ckpt_save()
822 fmd_error(EFMD_CKPT_NOMEM, "failed to build %s", ckp.ckp_src); in fmd_ckpt_save()
823 fmd_ckpt_destroy(&ckp); in fmd_ckpt_save()
832 fmd_ckpt_save_module(&ckp, mp); in fmd_ckpt_save()
833 err = fmd_ckpt_commit(&ckp); in fmd_ckpt_save()
834 fmd_ckpt_destroy(&ckp); in fmd_ckpt_save()
837 fmd_error(EFMD_CKPT_COMMIT, "failed to commit %s", ckp.ckp_dst); in fmd_ckpt_save()
856 fmd_ckpt_secptr(fmd_ckpt_t *ckp, fcf_secidx_t sid, uint_t type) in fmd_ckpt_secptr() argument
858 const fcf_sec_t *sp = (void *)(ckp->ckp_buf + in fmd_ckpt_secptr()
859 ckp->ckp_hdr->fcfh_secoff + ckp->ckp_hdr->fcfh_secsize * sid); in fmd_ckpt_secptr()
861 return (sid < ckp->ckp_secs && (sp->fcfs_type == type || in fmd_ckpt_secptr()
870 fmd_ckpt_dataptr(fmd_ckpt_t *ckp, const fcf_sec_t *sp) in fmd_ckpt_dataptr() argument
872 return (ckp->ckp_buf + sp->fcfs_offset); in fmd_ckpt_dataptr()
880 fmd_ckpt_datalim(fmd_ckpt_t *ckp, const fcf_sec_t *sp) in fmd_ckpt_datalim() argument
882 return (ckp->ckp_buf + sp->fcfs_offset + sp->fcfs_size); in fmd_ckpt_datalim()
890 fmd_ckpt_strptr(fmd_ckpt_t *ckp, fcf_stridx_t sid, const char *defstr) in fmd_ckpt_strptr() argument
892 return (sid < ckp->ckp_strn ? ckp->ckp_strs + sid : defstr); in fmd_ckpt_strptr()
896 fmd_ckpt_restore_events(fmd_ckpt_t *ckp, fcf_secidx_t sid, in fmd_ckpt_restore_events() argument
907 if ((sp = fmd_ckpt_secptr(ckp, sid, FCF_SECT_EVENTS)) == NULL) { in fmd_ckpt_restore_events()
908 fmd_ckpt_error(ckp, EFMD_CKPT_INVAL, in fmd_ckpt_restore_events()
915 fcfe = fmd_ckpt_dataptr(ckp, sp); in fmd_ckpt_restore_events()
955 fmd_ckpt_restore_suspects(fmd_ckpt_t *ckp, fmd_case_t *cp, fcf_secidx_t sid) in fmd_ckpt_restore_suspects() argument
962 if ((sp = fmd_ckpt_secptr(ckp, sid, FCF_SECT_NVLISTS)) == NULL) { in fmd_ckpt_restore_suspects()
963 fmd_ckpt_error(ckp, EFMD_CKPT_INVAL, in fmd_ckpt_restore_suspects()
967 fcfn = fmd_ckpt_dataptr(ckp, sp); in fmd_ckpt_restore_suspects()
968 endn = fmd_ckpt_datalim(ckp, sp); in fmd_ckpt_restore_suspects()
975 fmd_ckpt_error(ckp, EFMD_CKPT_INVAL, "nvlist %u [%d] " in fmd_ckpt_restore_suspects()
980 fmd_ckpt_error(ckp, EFMD_CKPT_INVAL, "failed to " in fmd_ckpt_restore_suspects()
996 fmd_ckpt_restore_bufs(fmd_ckpt_t *ckp, fmd_module_t *mp, in fmd_ckpt_restore_bufs() argument
1003 if ((sp = fmd_ckpt_secptr(ckp, sid, FCF_SECT_BUFS)) == NULL) { in fmd_ckpt_restore_bufs()
1004 fmd_ckpt_error(ckp, EFMD_CKPT_INVAL, in fmd_ckpt_restore_bufs()
1011 fcfb = fmd_ckpt_dataptr(ckp, sp); in fmd_ckpt_restore_bufs()
1015 dsp = fmd_ckpt_secptr(ckp, fcfb->fcfb_data, FCF_SECT_BUFFER); in fmd_ckpt_restore_bufs()
1018 fmd_ckpt_error(ckp, EFMD_CKPT_INVAL, "invalid %u " in fmd_ckpt_restore_bufs()
1023 fmd_ckpt_strptr(ckp, fcfb->fcfb_name, "<CORRUPT>"), in fmd_ckpt_restore_bufs()
1024 ckp->ckp_buf + dsp->fcfs_offset, dsp->fcfs_size); in fmd_ckpt_restore_bufs()
1031 fmd_ckpt_restore_case(fmd_ckpt_t *ckp, fmd_module_t *mp, const fcf_sec_t *sp) in fmd_ckpt_restore_case() argument
1033 const fcf_case_t *fcfc = fmd_ckpt_dataptr(ckp, sp); in fmd_ckpt_restore_case()
1034 const char *uuid = fmd_ckpt_strptr(ckp, fcfc->fcfc_uuid, NULL); in fmd_ckpt_restore_case()
1039 fmd_ckpt_error(ckp, EFMD_CKPT_INVAL, "corrupt %u case uuid " in fmd_ckpt_restore_case()
1040 "and/or state\n", (uint_t)(sp - ckp->ckp_secp)); in fmd_ckpt_restore_case()
1048 fmd_ckpt_error(ckp, EFMD_CKPT_INVAL, in fmd_ckpt_restore_case()
1052 fmd_ckpt_restore_events(ckp, fcfc->fcfc_principal, in fmd_ckpt_restore_case()
1055 fmd_ckpt_restore_events(ckp, fcfc->fcfc_events, in fmd_ckpt_restore_case()
1068 n = fmd_ckpt_restore_suspects(ckp, cp, fcfc->fcfc_suspects); in fmd_ckpt_restore_case()
1080 fmd_ckpt_restore_bufs(ckp, mp, cp, fcfc->fcfc_bufs); in fmd_ckpt_restore_case()
1084 fmd_ckpt_restore_serd(fmd_ckpt_t *ckp, fmd_module_t *mp, const fcf_sec_t *sp) in fmd_ckpt_restore_serd() argument
1086 const fcf_serd_t *fcfd = fmd_ckpt_dataptr(ckp, sp); in fmd_ckpt_restore_serd()
1092 esp = fmd_ckpt_secptr(ckp, fcfd->fcfd_events, FCF_SECT_EVENTS); in fmd_ckpt_restore_serd()
1095 fmd_ckpt_error(ckp, EFMD_CKPT_INVAL, in fmd_ckpt_restore_serd()
1099 if ((s = fmd_ckpt_strptr(ckp, fcfd->fcfd_name, NULL)) == NULL) { in fmd_ckpt_restore_serd()
1100 fmd_ckpt_error(ckp, EFMD_CKPT_INVAL, in fmd_ckpt_restore_serd()
1107 fmd_ckpt_restore_events(ckp, fcfd->fcfd_events, in fmd_ckpt_restore_serd()
1117 fmd_ckpt_restore_module(fmd_ckpt_t *ckp, fmd_module_t *mp) in fmd_ckpt_restore_module() argument
1119 const fcf_module_t *fcfm = fmd_ckpt_dataptr(ckp, ckp->ckp_modp); in fmd_ckpt_restore_module()
1123 if (strcmp(mp->mod_name, fmd_ckpt_strptr(ckp, fcfm->fcfm_name, "")) || in fmd_ckpt_restore_module()
1124 strcmp(mp->mod_path, fmd_ckpt_strptr(ckp, fcfm->fcfm_path, ""))) { in fmd_ckpt_restore_module()
1125 fmd_ckpt_error(ckp, EFMD_CKPT_INVAL, in fmd_ckpt_restore_module()
1129 for (i = 0; i < ckp->ckp_secs; i++) { in fmd_ckpt_restore_module()
1130 sp = (void *)(ckp->ckp_buf + in fmd_ckpt_restore_module()
1131 ckp->ckp_hdr->fcfh_secoff + ckp->ckp_hdr->fcfh_secsize * i); in fmd_ckpt_restore_module()
1135 fmd_ckpt_restore_case(ckp, mp, sp); in fmd_ckpt_restore_module()
1138 fmd_ckpt_restore_serd(ckp, mp, sp); in fmd_ckpt_restore_module()
1143 fmd_ckpt_restore_bufs(ckp, mp, NULL, fcfm->fcfm_bufs); in fmd_ckpt_restore_module()
1144 mp->mod_gen = ckp->ckp_hdr->fcfh_cgen; in fmd_ckpt_restore_module()
1155 fmd_ckpt_t ckp; in fmd_ckpt_restore() local
1162 if (fmd_ckpt_open(&ckp, mp) == -1) { in fmd_ckpt_restore()
1164 fmd_error(EFMD_CKPT_OPEN, "can't open %s", ckp.ckp_src); in fmd_ckpt_restore()
1170 fmd_ckpt_restore_module(&ckp, mp); in fmd_ckpt_restore()
1171 fmd_ckpt_destroy(&ckp); in fmd_ckpt_restore()