760 FCF_SECT_MODULE, sizeof (fcf_module_t));
761 }
762
763 void
764 fmd_ckpt_save(fmd_module_t *mp)
765 {
766 struct stat64 st;
767 char path[PATH_MAX];
768 mode_t dirmode;
769
770 hrtime_t now = gethrtime();
771 fmd_ckpt_t ckp;
772 int err;
773
774 ASSERT(fmd_module_locked(mp));
775
776 /*
777 * If checkpointing is disabled for the module, just return. We must
778 * commit the module state anyway to transition pending log events.
779 */
780 if (mp->mod_stats->ms_ckpt_save.fmds_value.bool == FMD_B_FALSE) {
781 fmd_module_commit(mp);
782 return;
783 }
784
785 if (!(mp->mod_flags & (FMD_MOD_MDIRTY | FMD_MOD_CDIRTY)))
786 return; /* no checkpoint is necessary for this module */
787
788 TRACE((FMD_DBG_CKPT, "ckpt save begin %s %llu",
789 mp->mod_name, mp->mod_gen + 1));
790
791 /*
792 * If the per-module checkpoint directory isn't found or isn't of type
793 * directory, move aside whatever is there (if anything) and attempt
794 * to mkdir(2) a new module checkpoint directory. If this fails, we
795 * have no choice but to abort the checkpoint and try again later.
796 */
797 if (stat64(mp->mod_ckpt, &st) != 0 || !S_ISDIR(st.st_mode)) {
798 (void) snprintf(path, sizeof (path), "%s-", mp->mod_ckpt);
799 (void) rename(mp->mod_ckpt, path);
800 (void) fmd_conf_getprop(fmd.d_conf, "ckpt.dirmode", &dirmode);
1137 case FCF_SECT_SERD:
1138 fmd_ckpt_restore_serd(ckp, mp, sp);
1139 break;
1140 }
1141 }
1142
1143 fmd_ckpt_restore_bufs(ckp, mp, NULL, fcfm->fcfm_bufs);
1144 mp->mod_gen = ckp->ckp_hdr->fcfh_cgen;
1145 }
1146
1147 /*
1148 * Restore a checkpoint for the specified module. Any errors which occur
1149 * during restore will call fmd_ckpt_error() or trigger an fmd_api_error(),
1150 * either of which will automatically unlock the module and trigger an abort.
1151 */
1152 void
1153 fmd_ckpt_restore(fmd_module_t *mp)
1154 {
1155 fmd_ckpt_t ckp;
1156
1157 if (mp->mod_stats->ms_ckpt_restore.fmds_value.bool == FMD_B_FALSE)
1158 return; /* never restore checkpoints for this module */
1159
1160 TRACE((FMD_DBG_CKPT, "ckpt restore begin %s", mp->mod_name));
1161
1162 if (fmd_ckpt_open(&ckp, mp) == -1) {
1163 if (errno != ENOENT)
1164 fmd_error(EFMD_CKPT_OPEN, "can't open %s", ckp.ckp_src);
1165 TRACE((FMD_DBG_CKPT, "ckpt restore end %s", mp->mod_name));
1166 return;
1167 }
1168
1169 ASSERT(!fmd_module_locked(mp));
1170 fmd_ckpt_restore_module(&ckp, mp);
1171 fmd_ckpt_destroy(&ckp);
1172 fmd_module_clrdirty(mp);
1173
1174 TRACE((FMD_DBG_CKPT, "ckpt restore end %s", mp->mod_name));
1175 fmd_dprintf(FMD_DBG_CKPT, "restored checkpoint of %s\n", mp->mod_name);
1176 }
1177
|
760 FCF_SECT_MODULE, sizeof (fcf_module_t));
761 }
762
763 void
764 fmd_ckpt_save(fmd_module_t *mp)
765 {
766 struct stat64 st;
767 char path[PATH_MAX];
768 mode_t dirmode;
769
770 hrtime_t now = gethrtime();
771 fmd_ckpt_t ckp;
772 int err;
773
774 ASSERT(fmd_module_locked(mp));
775
776 /*
777 * If checkpointing is disabled for the module, just return. We must
778 * commit the module state anyway to transition pending log events.
779 */
780 if (mp->mod_stats->ms_ckpt_save.fmds_value.b == FMD_B_FALSE) {
781 fmd_module_commit(mp);
782 return;
783 }
784
785 if (!(mp->mod_flags & (FMD_MOD_MDIRTY | FMD_MOD_CDIRTY)))
786 return; /* no checkpoint is necessary for this module */
787
788 TRACE((FMD_DBG_CKPT, "ckpt save begin %s %llu",
789 mp->mod_name, mp->mod_gen + 1));
790
791 /*
792 * If the per-module checkpoint directory isn't found or isn't of type
793 * directory, move aside whatever is there (if anything) and attempt
794 * to mkdir(2) a new module checkpoint directory. If this fails, we
795 * have no choice but to abort the checkpoint and try again later.
796 */
797 if (stat64(mp->mod_ckpt, &st) != 0 || !S_ISDIR(st.st_mode)) {
798 (void) snprintf(path, sizeof (path), "%s-", mp->mod_ckpt);
799 (void) rename(mp->mod_ckpt, path);
800 (void) fmd_conf_getprop(fmd.d_conf, "ckpt.dirmode", &dirmode);
1137 case FCF_SECT_SERD:
1138 fmd_ckpt_restore_serd(ckp, mp, sp);
1139 break;
1140 }
1141 }
1142
1143 fmd_ckpt_restore_bufs(ckp, mp, NULL, fcfm->fcfm_bufs);
1144 mp->mod_gen = ckp->ckp_hdr->fcfh_cgen;
1145 }
1146
1147 /*
1148 * Restore a checkpoint for the specified module. Any errors which occur
1149 * during restore will call fmd_ckpt_error() or trigger an fmd_api_error(),
1150 * either of which will automatically unlock the module and trigger an abort.
1151 */
1152 void
1153 fmd_ckpt_restore(fmd_module_t *mp)
1154 {
1155 fmd_ckpt_t ckp;
1156
1157 if (mp->mod_stats->ms_ckpt_restore.fmds_value.b == FMD_B_FALSE)
1158 return; /* never restore checkpoints for this module */
1159
1160 TRACE((FMD_DBG_CKPT, "ckpt restore begin %s", mp->mod_name));
1161
1162 if (fmd_ckpt_open(&ckp, mp) == -1) {
1163 if (errno != ENOENT)
1164 fmd_error(EFMD_CKPT_OPEN, "can't open %s", ckp.ckp_src);
1165 TRACE((FMD_DBG_CKPT, "ckpt restore end %s", mp->mod_name));
1166 return;
1167 }
1168
1169 ASSERT(!fmd_module_locked(mp));
1170 fmd_ckpt_restore_module(&ckp, mp);
1171 fmd_ckpt_destroy(&ckp);
1172 fmd_module_clrdirty(mp);
1173
1174 TRACE((FMD_DBG_CKPT, "ckpt restore end %s", mp->mod_name));
1175 fmd_dprintf(FMD_DBG_CKPT, "restored checkpoint of %s\n", mp->mod_name);
1176 }
1177
|