Exemplo n.º 1
0
/**
 * Prepare buffers for write request processing.
 *
 * This function converts remote buffers from client to local buffers
 * and prepares the latter. If there is recovery in progress and required
 * object is missing then it can be re-created before write.
 *
 * \param[in] env	execution environment
 * \param[in] exp	OBD export of client
 * \param[in] ofd	OFD device
 * \param[in] fid	FID of object
 * \param[in] la	object attributes
 * \param[in] oa	OBDO structure from client
 * \param[in] objcount	always 1
 * \param[in] obj	object data
 * \param[in] rnb	remote buffers
 * \param[in] nr_local	number of local buffers
 * \param[in] lnb	local buffers
 * \param[in] jobid	job ID name
 *
 * \retval		0 on successful prepare
 * \retval		negative value on error
 */
static int ofd_preprw_write(const struct lu_env *env, struct obd_export *exp,
			    struct ofd_device *ofd, const struct lu_fid *fid,
			    struct lu_attr *la, struct obdo *oa,
			    int objcount, struct obd_ioobj *obj,
			    struct niobuf_remote *rnb, int *nr_local,
			    struct niobuf_local *lnb, char *jobid)
{
	struct ofd_object	*fo;
	int			 i, j, k, rc = 0, tot_bytes = 0;

	ENTRY;
	LASSERT(env != NULL);
	LASSERT(objcount == 1);

	if (unlikely(exp->exp_obd->obd_recovering)) {
		u64 seq = fid_seq(fid);
		u64 oid = fid_oid(fid);
		struct ofd_seq *oseq;

		oseq = ofd_seq_load(env, ofd, seq);
		if (IS_ERR(oseq)) {
			CERROR("%s: Can't find FID Sequence "LPX64": rc = %d\n",
			       ofd_name(ofd), seq, (int)PTR_ERR(oseq));
			GOTO(out, rc = -EINVAL);
		}

		if (oid > ofd_seq_last_oid(oseq)) {
			int sync = 0;
			int diff;

			mutex_lock(&oseq->os_create_lock);
			diff = oid - ofd_seq_last_oid(oseq);

			/* Do sync create if the seq is about to used up */
			if (fid_seq_is_idif(seq) || fid_seq_is_mdt0(seq)) {
				if (unlikely(oid >= IDIF_MAX_OID - 1))
					sync = 1;
			} else if (fid_seq_is_norm(seq)) {
				if (unlikely(oid >=
					     LUSTRE_DATA_SEQ_MAX_WIDTH - 1))
					sync = 1;
			} else {
				CERROR("%s : invalid o_seq "DOSTID"\n",
				       ofd_name(ofd), POSTID(&oa->o_oi));
				mutex_unlock(&oseq->os_create_lock);
				ofd_seq_put(env, oseq);
				GOTO(out, rc = -EINVAL);
			}

			while (diff > 0) {
				u64 next_id = ofd_seq_last_oid(oseq) + 1;
				int count = ofd_precreate_batch(ofd, diff);

				rc = ofd_precreate_objects(env, ofd, next_id,
							   oseq, count, sync);
				if (rc < 0) {
					mutex_unlock(&oseq->os_create_lock);
					ofd_seq_put(env, oseq);
					GOTO(out, rc);
				}

				diff -= rc;
			}

			mutex_unlock(&oseq->os_create_lock);
		}

		ofd_seq_put(env, oseq);
	}

	fo = ofd_object_find(env, ofd, fid);
	if (IS_ERR(fo))
		GOTO(out, rc = PTR_ERR(fo));
	LASSERT(fo != NULL);

	ofd_read_lock(env, fo);
	if (!ofd_object_exists(fo)) {
		CERROR("%s: BRW to missing obj "DOSTID"\n",
		       exp->exp_obd->obd_name, POSTID(&obj->ioo_oid));
		ofd_read_unlock(env, fo);
		ofd_object_put(env, fo);
		GOTO(out, rc = -ENOENT);
	}

	if (ofd->ofd_lfsck_verify_pfid && oa->o_valid & OBD_MD_FLFID) {
		rc = ofd_verify_ff(env, fo, oa);
		if (rc != 0) {
			ofd_read_unlock(env, fo);
			ofd_object_put(env, fo);
			GOTO(out, rc);
		}
	}

	/* Process incoming grant info, set OBD_BRW_GRANTED flag and grant some
	 * space back if possible */
	ofd_grant_prepare_write(env, exp, oa, rnb, obj->ioo_bufcnt);

	/* parse remote buffers to local buffers and prepare the latter */
	*nr_local = 0;
	for (i = 0, j = 0; i < obj->ioo_bufcnt; i++) {
		rc = dt_bufs_get(env, ofd_object_child(fo),
				 rnb + i, lnb + j, 1);
		if (unlikely(rc < 0))
			GOTO(err, rc);
		LASSERT(rc <= PTLRPC_MAX_BRW_PAGES);
		/* correct index for local buffers to continue with */
		for (k = 0; k < rc; k++) {
			lnb[j+k].lnb_flags = rnb[i].rnb_flags;
			if (!(rnb[i].rnb_flags & OBD_BRW_GRANTED))
				lnb[j+k].lnb_rc = -ENOSPC;
		}
		j += rc;
		*nr_local += rc;
		LASSERT(j <= PTLRPC_MAX_BRW_PAGES);
		tot_bytes += rnb[i].rnb_len;
	}
	LASSERT(*nr_local > 0 && *nr_local <= PTLRPC_MAX_BRW_PAGES);

	rc = dt_write_prep(env, ofd_object_child(fo), lnb, *nr_local);
	if (unlikely(rc != 0))
		GOTO(err, rc);

	ofd_counter_incr(exp, LPROC_OFD_STATS_WRITE, jobid, tot_bytes);
	RETURN(0);
err:
	dt_bufs_put(env, ofd_object_child(fo), lnb, *nr_local);
	ofd_read_unlock(env, fo);
	ofd_object_put(env, fo);
	/* ofd_grant_prepare_write() was called, so we must commit */
	ofd_grant_commit(exp, oa->o_grant_used, rc);
out:
	/* let's still process incoming grant information packed in the oa,
	 * but without enforcing grant since we won't proceed with the write.
	 * Just like a read request actually. */
	ofd_grant_prepare_read(env, exp, oa);
	return rc;
}
Exemplo n.º 2
0
static int ofd_preprw_write(const struct lu_env *env, struct obd_export *exp,
                            struct ofd_device *ofd, struct lu_fid *fid,
                            struct lu_attr *la, struct obdo *oa,
                            int objcount, struct obd_ioobj *obj,
                            struct niobuf_remote *rnb, int *nr_local,
                            struct niobuf_local *lnb, char *jobid)
{
    struct ofd_object	*fo;
    int			 i, j, k, rc = 0, tot_bytes = 0;

    ENTRY;
    LASSERT(env != NULL);
    LASSERT(objcount == 1);

    if (unlikely(exp->exp_obd->obd_recovering)) {
        struct ofd_thread_info *info = ofd_info(env);

        /* copied from ofd_precreate_object */
        /* XXX this should be consolidated to use the same code
         *     instead of a copy, due to the ongoing risk of bugs. */
        memset(&info->fti_attr, 0, sizeof(info->fti_attr));
        info->fti_attr.la_valid = LA_TYPE | LA_MODE;
        info->fti_attr.la_mode = S_IFREG | S_ISUID | S_ISGID | 0666;
        info->fti_attr.la_valid |= LA_ATIME | LA_MTIME | LA_CTIME;
        /* Initialize a/c/m time so any client timestamp will always
         * be newer and update the inode. ctime = 0 is also handled
         * specially in osd_inode_setattr().  See LU-221, LU-1042 */
        info->fti_attr.la_atime = 0;
        info->fti_attr.la_mtime = 0;
        info->fti_attr.la_ctime = 0;

        fo = ofd_object_find_or_create(env, ofd, fid, &info->fti_attr);
    } else {
        fo = ofd_object_find(env, ofd, fid);
    }

    if (IS_ERR(fo))
        GOTO(out, rc = PTR_ERR(fo));
    LASSERT(fo != NULL);

    ofd_read_lock(env, fo);
    if (!ofd_object_exists(fo)) {
        CERROR("%s: BRW to missing obj "DOSTID"\n",
               exp->exp_obd->obd_name, POSTID(&obj->ioo_oid));
        ofd_read_unlock(env, fo);
        ofd_object_put(env, fo);
        GOTO(out, rc = -ENOENT);
    }

    /* Process incoming grant info, set OBD_BRW_GRANTED flag and grant some
     * space back if possible */
    ofd_grant_prepare_write(env, exp, oa, rnb, obj->ioo_bufcnt);

    /* parse remote buffers to local buffers and prepare the latter */
    *nr_local = 0;
    for (i = 0, j = 0; i < obj->ioo_bufcnt; i++) {
        rc = dt_bufs_get(env, ofd_object_child(fo),
                         rnb + i, lnb + j, 1,
                         ofd_object_capa(env, fo));
        if (unlikely(rc < 0))
            GOTO(err, rc);
        LASSERT(rc <= PTLRPC_MAX_BRW_PAGES);
        /* correct index for local buffers to continue with */
        for (k = 0; k < rc; k++) {
            lnb[j+k].lnb_flags = rnb[i].rnb_flags;
            if (!(rnb[i].rnb_flags & OBD_BRW_GRANTED))
                lnb[j+k].lnb_rc = -ENOSPC;

            /* remote client can't break through quota */
            if (exp_connect_rmtclient(exp))
                lnb[j+k].lnb_flags &= ~OBD_BRW_NOQUOTA;
        }
        j += rc;
        *nr_local += rc;
        LASSERT(j <= PTLRPC_MAX_BRW_PAGES);
        tot_bytes += rnb[i].rnb_len;
    }
    LASSERT(*nr_local > 0 && *nr_local <= PTLRPC_MAX_BRW_PAGES);

    rc = dt_write_prep(env, ofd_object_child(fo), lnb, *nr_local);
    if (unlikely(rc != 0))
        GOTO(err, rc);

    ofd_counter_incr(exp, LPROC_OFD_STATS_WRITE, jobid, tot_bytes);
    RETURN(0);
err:
    dt_bufs_put(env, ofd_object_child(fo), lnb, *nr_local);
    ofd_read_unlock(env, fo);
    /* ofd_grant_prepare_write() was called, so we must commit */
    ofd_grant_commit(env, exp, rc);
out:
    /* let's still process incoming grant information packed in the oa,
     * but without enforcing grant since we won't proceed with the write.
     * Just like a read request actually. */
    ofd_grant_prepare_read(env, exp, oa);
    return rc;
}