Ejemplo n.º 1
0
/** Add a CL_MARK record to the changelog
 * \param mdd
 * \param markerflags - CLM_*
 * \retval 0 ok
 */
int mdd_changelog_write_header(const struct lu_env *env,
			       struct mdd_device *mdd, int markerflags)
{
	struct obd_device		*obd = mdd2obd_dev(mdd);
	struct llog_changelog_rec	*rec;
	struct lu_buf			*buf;
	struct llog_ctxt		*ctxt;
	int				 reclen;
	int				 len = strlen(obd->obd_name);
	int				 rc;

	ENTRY;

	if (mdd->mdd_cl.mc_mask & (1 << CL_MARK)) {
		mdd->mdd_cl.mc_starttime = cfs_time_current_64();
		RETURN(0);
	}

	reclen = llog_data_len(sizeof(*rec) + len);
	buf = lu_buf_check_and_alloc(&mdd_env_info(env)->mti_big_buf, reclen);
	if (buf->lb_buf == NULL)
		RETURN(-ENOMEM);
	rec = buf->lb_buf;

        rec->cr.cr_flags = CLF_VERSION;
        rec->cr.cr_type = CL_MARK;
        rec->cr.cr_namelen = len;
	memcpy(changelog_rec_name(&rec->cr), obd->obd_name, rec->cr.cr_namelen);
        /* Status and action flags */
	rec->cr.cr_markerflags = mdd->mdd_cl.mc_flags | markerflags;
	rec->cr_hdr.lrh_len = llog_data_len(changelog_rec_size(&rec->cr) +
					    rec->cr.cr_namelen);
	rec->cr_hdr.lrh_type = CHANGELOG_REC;
	rec->cr.cr_time = cl_time();
	spin_lock(&mdd->mdd_cl.mc_lock);
	rec->cr.cr_index = ++mdd->mdd_cl.mc_index;
	spin_unlock(&mdd->mdd_cl.mc_lock);

	ctxt = llog_get_context(obd, LLOG_CHANGELOG_ORIG_CTXT);
	LASSERT(ctxt);

	rc = llog_cat_add(env, ctxt->loc_handle, &rec->cr_hdr, NULL);
	if (rc > 0)
		rc = 0;
	llog_ctxt_put(ctxt);

	/* assume on or off event; reset repeat-access time */
	mdd->mdd_cl.mc_starttime = cfs_time_current_64();
	RETURN(rc);
}
Ejemplo n.º 2
0
static int changelog_init_cb(const struct lu_env *env, struct llog_handle *llh,
			     struct llog_rec_hdr *hdr, void *data)
{
	struct mdd_device *mdd = (struct mdd_device *)data;
	struct llog_changelog_rec *rec = (struct llog_changelog_rec *)hdr;

	LASSERT(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN);
	LASSERT(rec->cr_hdr.lrh_type == CHANGELOG_REC);

	CDEBUG(D_INFO,
	       "seeing record at index %d/%d/"LPU64" t=%x %.*s in log"
	       DOSTID"\n", hdr->lrh_index, rec->cr_hdr.lrh_index,
	       rec->cr.cr_index, rec->cr.cr_type, rec->cr.cr_namelen,
	       changelog_rec_name(&rec->cr), POSTID(&llh->lgh_id.lgl_oi));

	mdd->mdd_cl.mc_index = rec->cr.cr_index;
	return LLOG_PROC_BREAK;
}
Ejemplo n.º 3
0
static int lustre_changelog_upcall(struct lustre_filesystem *lustre_fs,
				   const struct fsal_up_vector *event_func,
				   struct changelog_rec *rec)
{
	struct changelog_ext_jobid *jid;
	struct changelog_ext_rename *rnm;
	/* changelog are displayed with the format of "lfs changelog" */
	char format_chgl[] =
	  "%llu %02d%-5s %02d:%02d:%02d.%06d %04d.%02d.%02d 0x%x %s t="DFID;
	char message[LEN_MESSAGE];
	char message2[LEN_MESSAGE];

	struct tm ts;
	time_t secs;
	int rc;

	secs = rec->cr_time >> 30;
	gmtime_r(&secs, &ts);

	if (rec->cr_flags & CLF_JOBID)
		jid = changelog_rec_jobid(rec);
	else
		return -1;

	if (rec->cr_flags & CLF_RENAME)
		rnm = changelog_rec_rename(rec);
		snprintf(message, LEN_MESSAGE, format_chgl,
			rec->cr_index,
			rec->cr_type,
			changelog_type2str(rec->cr_type),
			ts.tm_hour,
			ts.tm_min,
			ts.tm_sec,
			(int)(rec->cr_time & ((1 << 30) - 1)),
			ts.tm_year + 1900,
			ts.tm_mon + 1,
			ts.tm_mday,
			rec->cr_flags & CLF_FLAGMASK,
			jid->cr_jobid,
			PFID(&rec->cr_tfid));

	if (rec->cr_namelen)
		snprintf(message2, LEN_MESSAGE,
			 " p="DFID" %.*s",
			 PFID(&rec->cr_pfid),
			 rec->cr_namelen,
			 changelog_rec_name(rec));
	else
		message2[0] = '\0';

	strncat(message, message2, LEN_MESSAGE);
	LogFullDebug(COMPONENT_FSAL_UP, "%s", message);

	switch (rec->cr_type) {
	case CL_CREATE:
	case CL_MKDIR:
	case CL_HARDLINK:
	case CL_SOFTLINK:
	case CL_MKNOD:
	case CL_UNLINK:
	case CL_RMDIR:
		/* invalidate parent entry */
		rc = lustre_invalidate_entry(lustre_fs,
					     event_func,
					     &rec->cr_pfid);
		if (rc)
			LogDebug(COMPONENT_FSAL,
				 "Could not invalidate fid="DFID,
				 PFID(&rec->cr_pfid));
		break;
	case CL_RENAME:
		/* invalidate parent entry
		 * and target entry */
		rc = lustre_invalidate_entry(lustre_fs,
					     event_func,
					     &rnm->cr_spfid);
		if (rc)
			LogDebug(COMPONENT_FSAL,
				 "Could not invalidate fid="DFID,
				 PFID(&rnm->cr_spfid));

		rc = lustre_invalidate_entry(lustre_fs,
					     event_func,
					     &rec->cr_pfid);
		if (rc)
			LogDebug(COMPONENT_FSAL,
				 "Could not invalidate fid="DFID,
				 PFID(&rec->cr_pfid));

		rc = lustre_invalidate_entry(lustre_fs,
					     event_func,
					     &rec->cr_tfid);
		if (rc)
			LogDebug(COMPONENT_FSAL,
				 "Could not invalidate fid="DFID,
				 PFID(&rec->cr_tfid));

		break;
	case CL_ATIME:
	case CL_MTIME:
	case CL_CTIME:
	case CL_SETATTR:
		/* invalidate target entry */
		rc = lustre_invalidate_entry(lustre_fs,
					     event_func,
					     &rec->cr_tfid);
		if (rc)
			LogDebug(COMPONENT_FSAL,
				 "Could not invalidate fid="DFID,
				 PFID(&rec->cr_tfid));
		break;
	default:
		/* untracked record type */
		break;
	}
	return 0;
}