osc_request.c

来自「lustre 1.6.5 source code」· C语言 代码 · 共 1,753 行 · 第 1/5 页

C
1,753
字号
/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * *  Copyright (C) 2001-2003 Cluster File Systems, Inc. *   Author Peter Braam <braam@clusterfs.com> * *   This file is part of the Lustre file system, http://www.lustre.org *   Lustre is a trademark of Cluster File Systems, Inc. * *   You may have signed or agreed to another license before downloading *   this software.  If so, you are bound by the terms and conditions *   of that agreement, and the following does not apply to you.  See the *   LICENSE file included with this distribution for more information. * *   If you did not agree to a different license, then this copy of Lustre *   is open source software; you can redistribute it and/or modify it *   under the terms of version 2 of the GNU General Public License as *   published by the Free Software Foundation. * *   In either case, Lustre is distributed in the hope that it will be *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *   license text for more details. * *  For testing and management it is treated as an obd_device, *  although * it does not export a full OBD method table (the *  requests are coming * in over the wire, so object target modules *  do not have a full * method table.) * */#ifndef EXPORT_SYMTAB# define EXPORT_SYMTAB#endif#define DEBUG_SUBSYSTEM S_OSC#ifdef __KERNEL__# include <libcfs/libcfs.h>#else /* __KERNEL__ */# include <liblustre.h>#endif# include <lustre_dlm.h>#include <libcfs/kp30.h>#include <lustre_net.h>#include <lustre/lustre_user.h>#include <obd_ost.h>#include <obd_lov.h>#ifdef  __CYGWIN__# include <ctype.h>#endif#include <lustre_ha.h>#include <lprocfs_status.h>#include <lustre_log.h>#include <lustre_debug.h>#include <lustre_param.h>#include <lustre_cache.h>#include "osc_internal.h"static quota_interface_t *quota_interface = NULL;extern quota_interface_t osc_quota_interface;static void osc_release_ppga(struct brw_page **ppga, obd_count count);int osc_cleanup(struct obd_device *obd);static quota_interface_t *quota_interface;extern quota_interface_t osc_quota_interface;/* by default 10s */atomic_t osc_resend_time; /* Pack OSC object metadata for disk storage (LE byte order). */static int osc_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,                      struct lov_stripe_md *lsm){        int lmm_size;        ENTRY;        lmm_size = sizeof(**lmmp);        if (!lmmp)                RETURN(lmm_size);        if (*lmmp && !lsm) {                OBD_FREE(*lmmp, lmm_size);                *lmmp = NULL;                RETURN(0);        }        if (!*lmmp) {                OBD_ALLOC(*lmmp, lmm_size);                if (!*lmmp)                        RETURN(-ENOMEM);        }        if (lsm) {                LASSERT(lsm->lsm_object_id);                (*lmmp)->lmm_object_id = cpu_to_le64(lsm->lsm_object_id);        }        RETURN(lmm_size);}/* Unpack OSC object metadata from disk storage (LE byte order). */static int osc_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,                        struct lov_mds_md *lmm, int lmm_bytes){        int lsm_size;        ENTRY;        if (lmm != NULL) {                if (lmm_bytes < sizeof (*lmm)) {                        CERROR("lov_mds_md too small: %d, need %d\n",                               lmm_bytes, (int)sizeof(*lmm));                        RETURN(-EINVAL);                }                /* XXX LOV_MAGIC etc check? */                if (lmm->lmm_object_id == 0) {                        CERROR("lov_mds_md: zero lmm_object_id\n");                        RETURN(-EINVAL);                }        }        lsm_size = lov_stripe_md_size(1);        if (lsmp == NULL)                RETURN(lsm_size);        if (*lsmp != NULL && lmm == NULL) {                OBD_FREE((*lsmp)->lsm_oinfo[0], sizeof(struct lov_oinfo));                OBD_FREE(*lsmp, lsm_size);                *lsmp = NULL;                RETURN(0);        }        if (*lsmp == NULL) {                OBD_ALLOC(*lsmp, lsm_size);                if (*lsmp == NULL)                        RETURN(-ENOMEM);                OBD_ALLOC((*lsmp)->lsm_oinfo[0], sizeof(struct lov_oinfo));                if ((*lsmp)->lsm_oinfo[0] == NULL) {                        OBD_FREE(*lsmp, lsm_size);                        RETURN(-ENOMEM);                }                loi_init((*lsmp)->lsm_oinfo[0]);        }        if (lmm != NULL) {                /* XXX zero *lsmp? */                (*lsmp)->lsm_object_id = le64_to_cpu (lmm->lmm_object_id);                LASSERT((*lsmp)->lsm_object_id);        }        (*lsmp)->lsm_maxbytes = LUSTRE_STRIPE_MAXBYTES;        RETURN(lsm_size);}static int osc_getattr_interpret(struct ptlrpc_request *req,                                 struct osc_async_args *aa, int rc){        struct ost_body *body;        ENTRY;        if (rc != 0)                GOTO(out, rc);        body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body),                                  lustre_swab_ost_body);        if (body) {                CDEBUG(D_INODE, "mode: %o\n", body->oa.o_mode);                memcpy(aa->aa_oi->oi_oa, &body->oa, sizeof(*aa->aa_oi->oi_oa));                /* This should really be sent by the OST */                aa->aa_oi->oi_oa->o_blksize = PTLRPC_MAX_BRW_SIZE;                aa->aa_oi->oi_oa->o_valid |= OBD_MD_FLBLKSZ;        } else {                CERROR("can't unpack ost_body\n");                rc = -EPROTO;                aa->aa_oi->oi_oa->o_valid = 0;        }out:        rc = aa->aa_oi->oi_cb_up(aa->aa_oi, rc);        RETURN(rc);}static int osc_getattr_async(struct obd_export *exp, struct obd_info *oinfo,                             struct ptlrpc_request_set *set){        struct ptlrpc_request *req;        struct ost_body *body;        int size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };        struct osc_async_args *aa;        ENTRY;        req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OST_VERSION,                              OST_GETATTR, 2, size,NULL);        if (!req)                RETURN(-ENOMEM);        body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));        memcpy(&body->oa, oinfo->oi_oa, sizeof(*oinfo->oi_oa));        ptlrpc_req_set_repsize(req, 2, size);        req->rq_interpret_reply = osc_getattr_interpret;        CLASSERT(sizeof(*aa) <= sizeof(req->rq_async_args));        aa = (struct osc_async_args *)&req->rq_async_args;        aa->aa_oi = oinfo;        ptlrpc_set_add_req(set, req);        RETURN (0);}static int osc_getattr(struct obd_export *exp, struct obd_info *oinfo){        struct ptlrpc_request *req;        struct ost_body *body;        int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };        ENTRY;        req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OST_VERSION,                              OST_GETATTR, 2, size, NULL);        if (!req)                RETURN(-ENOMEM);        body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));        memcpy(&body->oa, oinfo->oi_oa, sizeof(*oinfo->oi_oa));        ptlrpc_req_set_repsize(req, 2, size);        rc = ptlrpc_queue_wait(req);        if (rc) {                CERROR("%s failed: rc = %d\n", __FUNCTION__, rc);                GOTO(out, rc);        }        body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body),                                  lustre_swab_ost_body);        if (body == NULL) {                CERROR ("can't unpack ost_body\n");                GOTO (out, rc = -EPROTO);        }        CDEBUG(D_INODE, "mode: %o\n", body->oa.o_mode);        memcpy(oinfo->oi_oa, &body->oa, sizeof(*oinfo->oi_oa));        /* This should really be sent by the OST */        oinfo->oi_oa->o_blksize = PTLRPC_MAX_BRW_SIZE;        oinfo->oi_oa->o_valid |= OBD_MD_FLBLKSZ;        EXIT; out:        ptlrpc_req_finished(req);        return rc;}static int osc_setattr(struct obd_export *exp, struct obd_info *oinfo,                       struct obd_trans_info *oti){        struct ptlrpc_request *req;        struct ost_body *body;        int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };        ENTRY;        req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OST_VERSION,                              OST_SETATTR, 2, size, NULL);        if (!req)                RETURN(-ENOMEM);        body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));        memcpy(&body->oa, oinfo->oi_oa, sizeof(*oinfo->oi_oa));        ptlrpc_req_set_repsize(req, 2, size);        rc = ptlrpc_queue_wait(req);        if (rc)                GOTO(out, rc);        body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body),                                  lustre_swab_ost_body);        if (body == NULL)                GOTO(out, rc = -EPROTO);        memcpy(oinfo->oi_oa, &body->oa, sizeof(*oinfo->oi_oa));        EXIT;out:        ptlrpc_req_finished(req);        RETURN(rc);}static int osc_setattr_interpret(struct ptlrpc_request *req,                                 struct osc_async_args *aa, int rc){        struct ost_body *body;        ENTRY;        if (rc != 0)                GOTO(out, rc);        body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body),                                  lustre_swab_ost_body);        if (body == NULL) {                CERROR("can't unpack ost_body\n");                GOTO(out, rc = -EPROTO);        }        memcpy(aa->aa_oi->oi_oa, &body->oa, sizeof(*aa->aa_oi->oi_oa));out:        rc = aa->aa_oi->oi_cb_up(aa->aa_oi, rc);        RETURN(rc);}static int osc_setattr_async(struct obd_export *exp, struct obd_info *oinfo,                             struct obd_trans_info *oti,                             struct ptlrpc_request_set *rqset){        struct ptlrpc_request *req;        struct ost_body *body;        int size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };        struct osc_async_args *aa;        ENTRY;        req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_OST_VERSION,                              OST_SETATTR, 2, size, NULL);        if (!req)                RETURN(-ENOMEM);        body = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, sizeof(*body));        if (oinfo->oi_oa->o_valid & OBD_MD_FLCOOKIE) {                LASSERT(oti);                oinfo->oi_oa->o_lcookie = *oti->oti_logcookies;        }        memcpy(&body->oa, oinfo->oi_oa, sizeof(*oinfo->oi_oa));        ptlrpc_req_set_repsize(req, 2, size);        /* do mds to ost setattr asynchronouly */        if (!rqset) {                /* Do not wait for response. */                ptlrpcd_add_req(req);        } else {                req->rq_interpret_reply = osc_setattr_interpret;                CLASSERT(sizeof(*aa) <= sizeof(req->rq_async_args));                aa = (struct osc_async_args *)&req->rq_async_args;                aa->aa_oi = oinfo;                ptlrpc_set_add_req(rqset, req);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?