llog_lvfs.c

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

C
927
字号
                handle->lgh_id = *logid;        } else if (name) {                /* COMPAT_146 */                if (strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME) == 0) {                        handle->lgh_file = llog_filp_open(MDT_LOGS_DIR, name,                                                           open_flags, 0644);                } else {                        /* end COMPAT_146 */                        handle->lgh_file = llog_filp_open(MOUNT_CONFIGS_DIR,                                                          name, open_flags,                                                           0644);                }                if (IS_ERR(handle->lgh_file))                        GOTO(cleanup, rc = PTR_ERR(handle->lgh_file));                handle->lgh_id.lgl_ogr = 1;                handle->lgh_id.lgl_oid =                        handle->lgh_file->f_dentry->d_inode->i_ino;                handle->lgh_id.lgl_ogen =                        handle->lgh_file->f_dentry->d_inode->i_generation;        } else {                OBDO_ALLOC(oa);                if (oa == NULL)                        GOTO(cleanup, rc = -ENOMEM);                oa->o_gr = FILTER_GROUP_LLOG;                oa->o_valid = OBD_MD_FLGENER | OBD_MD_FLGROUP;                rc = obd_create(ctxt->loc_exp, oa, NULL, NULL);                if (rc)                        GOTO(cleanup, rc);                dchild = obd_lvfs_fid2dentry(ctxt->loc_exp, oa->o_id,                                             oa->o_generation, oa->o_gr);                if (IS_ERR(dchild))                        GOTO(cleanup, rc = PTR_ERR(dchild));                cleanup_phase = 2;                handle->lgh_file = l_dentry_open(&obd->obd_lvfs_ctxt, dchild,                                                 open_flags);                if (IS_ERR(handle->lgh_file))                        GOTO(cleanup, rc = PTR_ERR(handle->lgh_file));                handle->lgh_id.lgl_ogr = oa->o_gr;                handle->lgh_id.lgl_oid = oa->o_id;                handle->lgh_id.lgl_ogen = oa->o_generation;        }        handle->lgh_ctxt = ctxt; finish:        if (oa)                OBDO_FREE(oa);        RETURN(rc);cleanup:        switch (cleanup_phase) {        case 2:                l_dput(dchild);        case 1:                llog_free_handle(handle);        }        goto finish;}static int llog_lvfs_close(struct llog_handle *handle){        int rc;        ENTRY;        rc = filp_close(handle->lgh_file, 0);        if (rc)                CERROR("error closing log: rc %d\n", rc);        RETURN(rc);}static int llog_lvfs_destroy(struct llog_handle *handle){        struct dentry *fdentry;        struct obdo *oa;        struct obd_device *obd = handle->lgh_ctxt->loc_exp->exp_obd;        char *dir;        int rc;        ENTRY;        /* COMPAT_146 */        if (strcmp(obd->obd_type->typ_name, LUSTRE_MDS_NAME) == 0)                dir = MDT_LOGS_DIR;        else                /* end COMPAT_146 */                dir = MOUNT_CONFIGS_DIR;        fdentry = handle->lgh_file->f_dentry;        if (strcmp(fdentry->d_parent->d_name.name, dir) == 0) {                struct inode *inode = fdentry->d_parent->d_inode;                struct lvfs_run_ctxt saved;                push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);                dget(fdentry);                rc = llog_lvfs_close(handle);                if (rc == 0) {                        LOCK_INODE_MUTEX(inode);                        rc = vfs_unlink(inode, fdentry);                        UNLOCK_INODE_MUTEX(inode);                }                dput(fdentry);                pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);                RETURN(rc);        }        OBDO_ALLOC(oa);        if (oa == NULL)                RETURN(-ENOMEM);        oa->o_id = handle->lgh_id.lgl_oid;        oa->o_gr = handle->lgh_id.lgl_ogr;        oa->o_generation = handle->lgh_id.lgl_ogen;        oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP | OBD_MD_FLGENER;        rc = llog_lvfs_close(handle);        if (rc)                GOTO(out, rc);        rc = obd_destroy(handle->lgh_ctxt->loc_exp, oa, NULL, NULL, NULL); out:        OBDO_FREE(oa);        RETURN(rc);}/* reads the catalog list */int llog_get_cat_list(struct obd_device *obd, struct obd_device *disk_obd,                      char *name, int count, struct llog_catid *idarray){        struct lvfs_run_ctxt saved;        struct l_file *file;        int rc;        int size = sizeof(*idarray) * count;        loff_t off = 0;        ENTRY;        if (!count)                 RETURN(0);        push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);        file = filp_open(name, O_RDWR | O_CREAT | O_LARGEFILE, 0700);        if (!file || IS_ERR(file)) {                rc = PTR_ERR(file);                CERROR("OBD filter: cannot open/create %s: rc = %d\n",                       name, rc);                GOTO(out, rc);        }                if (!S_ISREG(file->f_dentry->d_inode->i_mode)) {                CERROR("%s is not a regular file!: mode = %o\n", name,                       file->f_dentry->d_inode->i_mode);                GOTO(out, rc = -ENOENT);        }        CDEBUG(D_CONFIG, "cat list: disk size=%d, read=%d\n",               (int)i_size_read(file->f_dentry->d_inode), size);        rc = fsfilt_read_record(disk_obd, file, idarray, size, &off);        if (rc) {                CERROR("OBD filter: error reading %s: rc %d\n", name, rc);                GOTO(out, rc);        }        EXIT; out:        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);        if (file && !IS_ERR(file))                rc = filp_close(file, 0);        return rc;}EXPORT_SYMBOL(llog_get_cat_list);/* writes the cat list */int llog_put_cat_list(struct obd_device *obd, struct obd_device *disk_obd,                      char *name, int count, struct llog_catid *idarray){        struct lvfs_run_ctxt saved;        struct l_file *file;        int rc;        int size = sizeof(*idarray) * count;        loff_t off = 0;        if (!count)                 return (0);        push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);        file = filp_open(name, O_RDWR | O_CREAT | O_LARGEFILE, 0700);        if (!file || IS_ERR(file)) {                rc = PTR_ERR(file);                CERROR("OBD filter: cannot open/create %s: rc = %d\n",                       name, rc);                GOTO(out, rc);        }        if (!S_ISREG(file->f_dentry->d_inode->i_mode)) {                CERROR("%s is not a regular file!: mode = %o\n", name,                       file->f_dentry->d_inode->i_mode);                GOTO(out, rc = -ENOENT);        }        rc = fsfilt_write_record(disk_obd, file, idarray, size, &off, 1);        if (rc) {                CDEBUG(D_INODE,"OBD filter: error reading %s: rc %d\n",                       name, rc);                GOTO(out, rc);        } out:        pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);        if (file && !IS_ERR(file))                rc = filp_close(file, 0);        RETURN(rc);}struct llog_operations llog_lvfs_ops = {        lop_write_rec:   llog_lvfs_write_rec,        lop_next_block:  llog_lvfs_next_block,        lop_prev_block:  llog_lvfs_prev_block,        lop_read_header: llog_lvfs_read_header,        lop_create:      llog_lvfs_create,        lop_destroy:     llog_lvfs_destroy,        lop_close:       llog_lvfs_close,        //        lop_cancel: llog_lvfs_cancel,};EXPORT_SYMBOL(llog_lvfs_ops);#else /* !__KERNEL__ */static int llog_lvfs_read_header(struct llog_handle *handle){        LBUG();        return 0;}static int llog_lvfs_write_rec(struct llog_handle *loghandle,                               struct llog_rec_hdr *rec,                               struct llog_cookie *reccookie, int cookiecount,                               void *buf, int idx){        LBUG();        return 0;}static int llog_lvfs_next_block(struct llog_handle *loghandle, int *cur_idx,                                int next_idx, __u64 *cur_offset, void *buf,                                int len){        LBUG();        return 0;}static int llog_lvfs_prev_block(struct llog_handle *loghandle,                                int prev_idx, void *buf, int len){        LBUG();        return 0;}static int llog_lvfs_create(struct llog_ctxt *ctxt, struct llog_handle **res,                            struct llog_logid *logid, char *name){        LBUG();        return 0;}static int llog_lvfs_close(struct llog_handle *handle){        LBUG();        return 0;}static int llog_lvfs_destroy(struct llog_handle *handle){        LBUG();        return 0;}int llog_get_cat_list(struct obd_device *obd, struct obd_device *disk_obd,                      char *name, int count, struct llog_catid *idarray){        LBUG();        return 0;}int llog_put_cat_list(struct obd_device *obd, struct obd_device *disk_obd,                      char *name, int count, struct llog_catid *idarray){        LBUG();        return 0;}struct llog_operations llog_lvfs_ops = {        lop_write_rec:   llog_lvfs_write_rec,        lop_next_block:  llog_lvfs_next_block,        lop_prev_block:  llog_lvfs_prev_block,        lop_read_header: llog_lvfs_read_header,        lop_create:      llog_lvfs_create,        lop_destroy:     llog_lvfs_destroy,        lop_close:       llog_lvfs_close,//        lop_cancel:      llog_lvfs_cancel,};#endif

⌨️ 快捷键说明

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