⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mdc_request.c

📁 lustre 1.6.5 source code
💻 C
📖 第 1 页 / 共 4 页
字号:
/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * * Copyright (C) 2001-2003 Cluster File Systems, Inc. * *   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. */#ifndef EXPORT_SYMTAB# define EXPORT_SYMTAB#endif#define DEBUG_SUBSYSTEM S_MDC#ifdef __KERNEL__# include <linux/module.h># include <linux/pagemap.h># include <linux/miscdevice.h># include <linux/init.h>#else# include <liblustre.h>#endif#include <obd_class.h>#include <lustre_dlm.h>#include <lprocfs_status.h>#include <lustre_param.h>#include "mdc_internal.h"static quota_interface_t *quota_interface;#define REQUEST_MINOR 244static quota_interface_t *quota_interface;extern quota_interface_t mdc_quota_interface;static int mdc_cleanup(struct obd_device *obd);extern int mds_queue_req(struct ptlrpc_request *);/* Helper that implements most of mdc_getstatus and signal_completed_replay. *//* XXX this should become mdc_get_info("key"), sending MDS_GET_INFO RPC */static int send_getstatus(struct obd_import *imp, struct ll_fid *rootfid,                          int level, int msg_flags){        struct ptlrpc_request *req;        struct mds_body *body;        int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };        ENTRY;        req = ptlrpc_prep_req(imp, LUSTRE_MDS_VERSION, MDS_GETSTATUS, 2, size,                              NULL);        if (!req)                GOTO(out, rc = -ENOMEM);        req->rq_send_state = level;        ptlrpc_req_set_repsize(req, 2, size);        mdc_pack_req_body(req, REQ_REC_OFF, 0, NULL, 0, 0);        lustre_msg_add_flags(req->rq_reqmsg, msg_flags);        rc = ptlrpc_queue_wait(req);        if (!rc) {                body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body),                                          lustre_swab_mds_body);                if (body == NULL) {                        CERROR ("Can't extract mds_body\n");                        GOTO (out, rc = -EPROTO);                }                memcpy(rootfid, &body->fid1, sizeof(*rootfid));                CDEBUG(D_NET, "root ino="LPU64", last_committed="LPU64                       ", last_xid="LPU64"\n",                       rootfid->id,                       lustre_msg_get_last_committed(req->rq_repmsg),                       lustre_msg_get_last_xid(req->rq_repmsg));        }        EXIT; out:        ptlrpc_req_finished(req);        return rc;}/* This should be mdc_get_info("rootfid") */int mdc_getstatus(struct obd_export *exp, struct ll_fid *rootfid){        return send_getstatus(class_exp2cliimp(exp), rootfid, LUSTRE_IMP_FULL,                              0);}staticint mdc_getattr_common(struct obd_export *exp, unsigned int ea_size,                        unsigned int acl_size, struct ptlrpc_request *req){        struct obd_device *obddev = class_exp2obd(exp);        struct mds_body *body;        void *eadata;        int size[4] = { sizeof(struct ptlrpc_body), sizeof(*body) };        int bufcount = 2, rc;        ENTRY;        /* request message already built */        if (ea_size != 0) {                size[bufcount++] = ea_size;                CDEBUG(D_INODE, "reserved %u bytes for MD/symlink in packet\n",                       ea_size);        }        if (acl_size) {                size[bufcount++] = acl_size;                CDEBUG(D_INODE, "reserved %u bytes for ACL\n", acl_size);        }        ptlrpc_req_set_repsize(req, bufcount, size);        mdc_enter_request(&obddev->u.cli);        rc = ptlrpc_queue_wait(req);        mdc_exit_request(&obddev->u.cli);        if (rc != 0)                RETURN (rc);        body = lustre_swab_repbuf(req, REPLY_REC_OFF, sizeof(*body),                                  lustre_swab_mds_body);        if (body == NULL) {                CERROR ("Can't unpack mds_body\n");                RETURN (-EPROTO);        }        CDEBUG(D_NET, "mode: %o\n", body->mode);        lustre_set_rep_swabbed(req, REPLY_REC_OFF + 1);        if (body->eadatasize != 0) {                /* reply indicates presence of eadata; check it's there... */                eadata = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF + 1,                                        body->eadatasize);                if (eadata == NULL) {                        CERROR ("Missing/short eadata\n");                        RETURN (-EPROTO);                }        }                if (body->valid & OBD_MD_FLMODEASIZE) {                if (exp->exp_obd->u.cli.cl_max_mds_easize < body->max_mdsize)                         exp->exp_obd->u.cli.cl_max_mds_easize =                                                 body->max_mdsize;                if (exp->exp_obd->u.cli.cl_max_mds_cookiesize <                                                 body->max_cookiesize)                        exp->exp_obd->u.cli.cl_max_mds_cookiesize =                                                 body->max_cookiesize;        }        RETURN (0);}int mdc_getattr(struct obd_export *exp, struct ll_fid *fid,                obd_valid valid, unsigned int ea_size,                struct ptlrpc_request **request){        struct ptlrpc_request *req;        int size[2] = { sizeof(struct ptlrpc_body), sizeof(struct mds_body) };        int acl_size = 0, rc;        ENTRY;        /* XXX do we need to make another request here?  We just did a getattr         *     to do the lookup in the first place.         */        req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,                              MDS_GETATTR, 2, size, NULL);        if (!req)                GOTO(out, rc = -ENOMEM);        mdc_pack_req_body(req, REQ_REC_OFF, valid, fid, ea_size,                          MDS_BFLAG_EXT_FLAGS/*request "new" flags(bug 9486)*/);        /* currently only root inode will call us with FLACL */        if (valid & OBD_MD_FLACL)                acl_size = LUSTRE_POSIX_ACL_MAX_SIZE;        rc = mdc_getattr_common(exp, ea_size, acl_size, req);        if (rc != 0) {                ptlrpc_req_finished (req);                req = NULL;        } out:        *request = req;        RETURN (rc);}int mdc_getattr_name(struct obd_export *exp, struct ll_fid *fid,                     const char *filename, int namelen, unsigned long valid,                     unsigned int ea_size, struct ptlrpc_request **request){        struct ptlrpc_request *req;        struct mds_body *body;        int rc, size[3] = { sizeof(struct ptlrpc_body), sizeof(*body), namelen};        ENTRY;        req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,                              MDS_GETATTR_NAME, 3, size, NULL);        if (!req)                GOTO(out, rc = -ENOMEM);        mdc_pack_req_body(req, REQ_REC_OFF, valid, fid, ea_size,                          MDS_BFLAG_EXT_FLAGS/*request "new" flags(bug 9486)*/);         LASSERT(strnlen(filename, namelen) == namelen - 1);        memcpy(lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, namelen),               filename, namelen);        rc = mdc_getattr_common(exp, ea_size, 0, req);        if (rc != 0) {                ptlrpc_req_finished (req);                req = NULL;        } out:        *request = req;        RETURN(rc);}staticint mdc_xattr_common(struct obd_export *exp, struct ll_fid *fid,                     int opcode, obd_valid valid, const char *xattr_name,                     const char *input, int input_size, int output_size,                     int flags, struct ptlrpc_request **request){        struct obd_device *obddev = class_exp2obd(exp);        struct ptlrpc_request *req;        int size[4] = { sizeof(struct ptlrpc_body), sizeof(struct mds_body) };        // int size[3] = {sizeof(struct mds_body)}, bufcnt = 1;        int rc, xattr_namelen = 0, bufcnt = 2, offset;        void *tmp;        ENTRY;        if (xattr_name) {                xattr_namelen = strlen(xattr_name) + 1;                size[bufcnt++] = xattr_namelen;        }        if (input_size) {                LASSERT(input);                size[bufcnt++] = input_size;        }        req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_MDS_VERSION,                              opcode, bufcnt, size, NULL);        if (!req)                GOTO(out, rc = -ENOMEM);        /* request data */        mdc_pack_req_body(req, REQ_REC_OFF, valid, fid, output_size, flags);        offset = REQ_REC_OFF + 1;        if (xattr_name) {                tmp = lustre_msg_buf(req->rq_reqmsg, offset++, xattr_namelen);                memcpy(tmp, xattr_name, xattr_namelen);        }        if (input_size) {                tmp = lustre_msg_buf(req->rq_reqmsg, offset++, input_size);                memcpy(tmp, input, input_size);        }        /* reply buffers */        if (opcode == MDS_GETXATTR) {                size[REPLY_REC_OFF] = sizeof(struct mds_body);                bufcnt = 2;        } else {                bufcnt = 1;        }        /* we do this even output_size is 0, because server is doing that */        size[bufcnt++] = output_size;        ptlrpc_req_set_repsize(req, bufcnt, size);        /* make rpc */        if (opcode == MDS_SETXATTR)                mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);        else                mdc_enter_request(&obddev->u.cli);        rc = ptlrpc_queue_wait(req);        if (opcode == MDS_SETXATTR)                mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);        else                mdc_exit_request(&obddev->u.cli);        if (rc != 0)                GOTO(err_out, rc);        if (opcode == MDS_GETXATTR) {                struct mds_body * body = lustre_swab_repbuf(req, REPLY_REC_OFF,                                          sizeof(*body),                                          lustre_swab_mds_body);                if (body == NULL) {                        CERROR ("Can't unpack mds_body\n");                        GOTO(err_out, rc = -EPROTO);                }        }out:        *request = req;        RETURN (rc);err_out:        ptlrpc_req_finished(req);        req = NULL;        goto out;}int mdc_setxattr(struct obd_export *exp, struct ll_fid *fid,                 obd_valid valid, const char *xattr_name,                 const char *input, int input_size,                 int output_size, int flags,                 struct ptlrpc_request **request){        return mdc_xattr_common(exp, fid, MDS_SETXATTR, valid, xattr_name,                                input, input_size, output_size, flags, request);}int mdc_getxattr(struct obd_export *exp, struct ll_fid *fid,                 obd_valid valid, const char *xattr_name,                 const char *input, int input_size,                 int output_size, struct ptlrpc_request **request){        return mdc_xattr_common(exp, fid, MDS_GETXATTR, valid, xattr_name,                                input, input_size, output_size, 0, request);}/* This should be called with both the request and the reply still packed. */void mdc_store_inode_generation(struct ptlrpc_request *req, int reqoff,                                int repoff){        struct mds_rec_create *rec = lustre_msg_buf(req->rq_reqmsg, reqoff,                                                    sizeof(*rec));        struct mds_body *body = lustre_msg_buf(req->rq_repmsg, repoff,                                               sizeof(*body));        LASSERT (rec != NULL);        LASSERT (body != NULL);        memcpy(&rec->cr_replayfid, &body->fid1, sizeof rec->cr_replayfid);        if (body->fid1.id == 0) {                DEBUG_REQ(D_ERROR, req, "saving replay request with id = 0 "                          "gen = %u", body->fid1.generation);                LBUG();

⌨️ 快捷键说明

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