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

📄 handler.c

📁 lustre 1.6.5 source code
💻 C
📖 第 1 页 / 共 5 页
字号:
                                  lustre_swab_mds_body);        if (body == NULL)                RETURN(-EFAULT);        rc = mds_init_ucred(&uc, req, offset);        if (rc)                GOTO(out_ucred, rc);        push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);        de = mds_fid2dentry(mds, &body->fid1, NULL);        if (IS_ERR(de)) {                rc = req->rq_status = PTR_ERR(de);                GOTO(out_pop, rc);        }        rc = mds_getattr_pack_msg(req, de->d_inode, offset);        if (rc != 0) {                CERROR("mds_getattr_pack_msg: %d\n", rc);                GOTO(out_pop, rc);        }        req->rq_status = mds_getattr_internal(obd, de, req, body,REPLY_REC_OFF);        l_dput(de);        GOTO(out_pop, rc);out_pop:        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);out_ucred:        if (!req->rq_packed_final) {                int rc2 = lustre_pack_reply(req, 1, NULL, NULL);                if (rc == 0)                        rc = rc2;                req->rq_status = rc;        }        mds_exit_ucred(&uc, mds);        return rc;}static int mds_obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,                          __u64 max_age, __u32 flags){        int rc;        spin_lock(&obd->obd_osfs_lock);        rc = fsfilt_statfs(obd, obd->u.obt.obt_sb, max_age);        if (rc == 0)                memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));        spin_unlock(&obd->obd_osfs_lock);        return rc;}static int mds_statfs(struct ptlrpc_request *req){        struct obd_device *obd = req->rq_export->exp_obd;        struct ptlrpc_service *svc = req->rq_rqbd->rqbd_service;        int rc, size[2] = { sizeof(struct ptlrpc_body),                            sizeof(struct obd_statfs) };        ENTRY;        /* This will trigger a watchdog timeout */        OBD_FAIL_TIMEOUT(OBD_FAIL_MDS_STATFS_LCW_SLEEP,                         (MDS_SERVICE_WATCHDOG_FACTOR *                           at_get(&svc->srv_at_estimate) / 1000) + 1);        OBD_COUNTER_INCREMENT(obd, statfs);        if (OBD_FAIL_CHECK(OBD_FAIL_MDS_STATFS_PACK))                GOTO(out, rc = -ENOMEM);        rc = lustre_pack_reply(req, 2, size, NULL);        if (rc)                GOTO(out, rc);        /* We call this so that we can cache a bit - 1 jiffie worth */        rc = mds_obd_statfs(obd, lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,                                                size[REPLY_REC_OFF]),                            cfs_time_current_64() - HZ, 0);        if (rc) {                CERROR("mds_obd_statfs failed: rc %d\n", rc);                GOTO(out, rc);        }        EXIT;out:        req->rq_status = rc;        return 0;}static int mds_sync(struct ptlrpc_request *req, int offset){        struct obd_device *obd = req->rq_export->exp_obd;        struct mds_obd *mds = &obd->u.mds;        struct mds_body *body;        int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };        ENTRY;        body = lustre_swab_reqbuf(req, offset, sizeof(*body),                                  lustre_swab_mds_body);        if (body == NULL)                GOTO(out, rc = -EFAULT);        if (OBD_FAIL_CHECK(OBD_FAIL_MDS_SYNC_PACK))                GOTO(out, rc = -ENOMEM);        rc = lustre_pack_reply(req, 2, size, NULL);        if (rc)                GOTO(out, rc);        rc = fsfilt_sync(obd, obd->u.obt.obt_sb);        if (rc == 0 && body->fid1.id != 0) {                struct dentry *de;                de = mds_fid2dentry(mds, &body->fid1, NULL);                if (IS_ERR(de))                        GOTO(out, rc = PTR_ERR(de));                body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,                                      sizeof(*body));                mds_pack_inode2fid(&body->fid1, de->d_inode);                mds_pack_inode2body(body, de->d_inode);                l_dput(de);        }        GOTO(out, rc);out:        req->rq_status = rc;        return 0;}/* mds_readpage does not take a DLM lock on the inode, because the client must * already have a PR lock. * * If we were to take another one here, a deadlock will result, if another * thread is already waiting for a PW lock. */static int mds_readpage(struct ptlrpc_request *req, int offset){        struct obd_device *obd = req->rq_export->exp_obd;        struct mds_obd *mds = &obd->u.mds;        struct vfsmount *mnt;        struct dentry *de;        struct file *file;        struct mds_body *body, *repbody;        struct lvfs_run_ctxt saved;        int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repbody) };        struct lvfs_ucred uc = {NULL,};        ENTRY;        OBD_FAIL_RETURN(OBD_FAIL_MDS_READPAGE_PACK, -ENOMEM);        rc = lustre_pack_reply(req, 2, size, NULL);        if (rc)                GOTO(out, rc);        body = lustre_swab_reqbuf(req, offset, sizeof(*body),                                  lustre_swab_mds_body);        if (body == NULL)                GOTO (out, rc = -EFAULT);        rc = mds_init_ucred(&uc, req, offset);        if (rc)                GOTO(out, rc);        push_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);        de = mds_fid2dentry(&obd->u.mds, &body->fid1, &mnt);        if (IS_ERR(de))                GOTO(out_pop, rc = PTR_ERR(de));        CDEBUG(D_INODE, "ino %lu\n", de->d_inode->i_ino);        file = dentry_open(de, mnt, O_RDONLY | O_LARGEFILE);        /* note: in case of an error, dentry_open puts dentry */        if (IS_ERR(file))                GOTO(out_pop, rc = PTR_ERR(file));        /* body->size is actually the offset -eeb */        if ((body->size & (de->d_inode->i_sb->s_blocksize - 1)) != 0) {                CERROR("offset "LPU64" not on a block boundary of %lu\n",                       body->size, de->d_inode->i_sb->s_blocksize);                GOTO(out_file, rc = -EFAULT);        }        /* body->nlink is actually the #bytes to read -eeb */        if (body->nlink & (de->d_inode->i_sb->s_blocksize - 1)) {                CERROR("size %u is not multiple of blocksize %lu\n",                       body->nlink, de->d_inode->i_sb->s_blocksize);                GOTO(out_file, rc = -EFAULT);        }        repbody = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF,                                 sizeof(*repbody));        repbody->size = i_size_read(file->f_dentry->d_inode);        repbody->valid = OBD_MD_FLSIZE;        /* to make this asynchronous make sure that the handling function           doesn't send a reply when this function completes. Instead a           callback function would send the reply */        /* body->size is actually the offset -eeb */        rc = mds_sendpage(req, file, body->size, body->nlink);out_file:        filp_close(file, 0);out_pop:        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, &uc);out:        mds_exit_ucred(&uc, mds);        req->rq_status = rc;        RETURN(0);}int mds_reint(struct ptlrpc_request *req, int offset,              struct lustre_handle *lockh){        struct mds_update_record *rec; /* 116 bytes on the stack?  no sir! */        int rc;        OBD_ALLOC(rec, sizeof(*rec));        if (rec == NULL)                RETURN(-ENOMEM);        rc = mds_update_unpack(req, offset, rec);        if (rc || OBD_FAIL_CHECK(OBD_FAIL_MDS_REINT_UNPACK)) {                CERROR("invalid record\n");                GOTO(out, req->rq_status = -EINVAL);        }        mds_root_squash(&req->rq_export->exp_obd->u.mds, &req->rq_peer.nid,                        &rec->ur_uc.luc_fsuid, &rec->ur_uc.luc_fsgid,                        &rec->ur_uc.luc_cap, &rec->ur_uc.luc_suppgid1,                        &rec->ur_uc.luc_suppgid2);        /* rc will be used to interrupt a for loop over multiple records */        rc = mds_reint_rec(rec, offset, req, lockh); out:        OBD_FREE(rec, sizeof(*rec));        return rc;}static int mds_filter_recovery_request(struct ptlrpc_request *req,                                       struct obd_device *obd, int *process){        switch (lustre_msg_get_opc(req->rq_reqmsg)) {        case MDS_CONNECT: /* This will never get here, but for completeness. */        case OST_CONNECT: /* This will never get here, but for completeness. */        case MDS_DISCONNECT:        case OST_DISCONNECT:               *process = 1;               RETURN(0);        case MDS_CLOSE:        case MDS_SYNC: /* used in unmounting */        case OBD_PING:        case MDS_REINT:        case LDLM_ENQUEUE:                *process = target_queue_recovery_request(req, obd);                RETURN(0);        default:                DEBUG_REQ(D_ERROR, req, "not permitted during recovery");                *process = 0;                /* XXX what should we set rq_status to here? */                req->rq_status = -EAGAIN;                RETURN(ptlrpc_error(req));        }}static char *reint_names[] = {        [REINT_SETATTR] "setattr",        [REINT_CREATE]  "create",        [REINT_LINK]    "link",        [REINT_UNLINK]  "unlink",        [REINT_RENAME]  "rename",        [REINT_OPEN]    "open",};static int mds_set_info_rpc(struct obd_export *exp, struct ptlrpc_request *req){        void *key, *val;        int keylen, vallen, rc = 0;        ENTRY;        key = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF, 1);        if (key == NULL) {                DEBUG_REQ(D_HA, req, "no set_info key");                RETURN(-EFAULT);        }        keylen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF);        val = lustre_msg_buf(req->rq_reqmsg, REQ_REC_OFF + 1, 0);        vallen = lustre_msg_buflen(req->rq_reqmsg, REQ_REC_OFF + 1);        rc = lustre_pack_reply(req, 1, NULL, NULL);        if (rc)                RETURN(rc);        lustre_msg_set_status(req->rq_repmsg, 0);        if (KEY_IS("read-only")) {                if (val == NULL || vallen < sizeof(__u32)) {                        DEBUG_REQ(D_HA, req, "no set_info val");                        RETURN(-EFAULT);                }                if (*(__u32 *)val)                        exp->exp_connect_flags |= OBD_CONNECT_RDONLY;                else                        exp->exp_connect_flags &= ~OBD_CONNECT_RDONLY;        } else {                RETURN(-EINVAL);        }        RETURN(0);}static int mds_handle_quotacheck(struct ptlrpc_request *req){        struct obd_quotactl *oqctl;        int rc;        ENTRY;        oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),                                   lustre_swab_obd_quotactl);        if (oqctl == NULL)                RETURN(-EPROTO);        rc = lustre_pack_reply(req, 1, NULL, NULL);        if (rc)                RETURN(rc);        req->rq_status = obd_quotacheck(req->rq_export, oqctl);        RETURN(0);}static int mds_handle_quotactl(struct ptlrpc_request *req){        struct obd_quotactl *oqctl, *repoqc;        int rc, size[2] = { sizeof(struct ptlrpc_body), sizeof(*repoqc) };        ENTRY;        oqctl = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*oqctl),                                   lustre_swab_obd_quotactl);        if (oqctl == NULL)                RETURN(-EPROTO);        rc = lustre_pack_reply(req, 2, size, NULL);        if (rc)                RETURN(rc);        repoqc = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*repoqc));        req->rq_status = obd_quotactl(req->rq_export, oqctl);        *repoqc = *oqctl;        RETURN(0);}static int mds_msg_check_version(struct lustre_msg *msg){        int rc;

⌨️ 快捷键说明

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