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

📄 llog_cat.c

📁 lustre 1.6.5 source code
💻 C
📖 第 1 页 / 共 2 页
字号:
        /* loghandle is already locked by llog_cat_current_log() for us */        rc = llog_write_rec(loghandle, rec, reccookie, 1, buf, -1);        up_write(&loghandle->lgh_lock);        if (rc == -ENOSPC) {                /* to create a new plain log */                loghandle = llog_cat_current_log(cathandle, 1);                if (IS_ERR(loghandle))                        RETURN(PTR_ERR(loghandle));                rc = llog_write_rec(loghandle, rec, reccookie, 1, buf, -1);                up_write(&loghandle->lgh_lock);        }        RETURN(rc);}EXPORT_SYMBOL(llog_cat_add_rec);/* For each cookie in the cookie array, we clear the log in-use bit and either: * - the log is empty, so mark it free in the catalog header and delete it * - the log is not empty, just write out the log header * * The cookies may be in different log files, so we need to get new logs * each time. * * Assumes caller has already pushed us into the kernel context. */int llog_cat_cancel_records(struct llog_handle *cathandle, int count,                        struct llog_cookie *cookies){        int i, index, rc = 0;        ENTRY;        down_write(&cathandle->lgh_lock);        for (i = 0; i < count; i++, cookies++) {                struct llog_handle *loghandle;                struct llog_logid *lgl = &cookies->lgc_lgl;                rc = llog_cat_id2handle(cathandle, &loghandle, lgl);                if (rc) {                        CERROR("Cannot find log "LPX64"\n", lgl->lgl_oid);                        break;                }                down_write(&loghandle->lgh_lock);                rc = llog_cancel_rec(loghandle, cookies->lgc_index);                up_write(&loghandle->lgh_lock);                if (rc == 1) {          /* log has been destroyed */                        index = loghandle->u.phd.phd_cookie.lgc_index;                        if (cathandle->u.chd.chd_current_log == loghandle)                                cathandle->u.chd.chd_current_log = NULL;                        llog_free_handle(loghandle);                        LASSERT(index);                        llog_cat_set_first_idx(cathandle, index);                        rc = llog_cancel_rec(cathandle, index);                        if (rc == 0)                                CDEBUG(D_RPCTRACE,"cancel plain log at index %u"                                       " of catalog "LPX64"\n",                                       index, cathandle->lgh_id.lgl_oid);                }        }        up_write(&cathandle->lgh_lock);        RETURN(rc);}EXPORT_SYMBOL(llog_cat_cancel_records);int llog_cat_process_cb(struct llog_handle *cat_llh, struct llog_rec_hdr *rec,                        void *data){        struct llog_process_data *d = data;        struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;        struct llog_handle *llh;        int rc;        ENTRY;        if (rec->lrh_type != LLOG_LOGID_MAGIC) {                CERROR("invalid record in catalog\n");                RETURN(-EINVAL);        }        CDEBUG(D_HA, "processing log "LPX64":%x at index %u of catalog "               LPX64"\n", lir->lid_id.lgl_oid, lir->lid_id.lgl_ogen,               rec->lrh_index, cat_llh->lgh_id.lgl_oid);        rc = llog_cat_id2handle(cat_llh, &llh, &lir->lid_id);        if (rc) {                CERROR("Cannot find handle for log "LPX64"\n",                       lir->lid_id.lgl_oid);                RETURN(rc);        }        rc = llog_process(llh, d->lpd_cb, d->lpd_data, NULL);        RETURN(rc);}int llog_cat_process(struct llog_handle *cat_llh, llog_cb_t cb, void *data){        struct llog_process_data d;        struct llog_process_cat_data cd;        struct llog_log_hdr *llh = cat_llh->lgh_hdr;        int rc;        ENTRY;        LASSERT(llh->llh_flags & LLOG_F_IS_CAT);        d.lpd_data = data;        d.lpd_cb = cb;        if (llh->llh_cat_idx > cat_llh->lgh_last_idx) {                CWARN("catlog "LPX64" crosses index zero\n",                      cat_llh->lgh_id.lgl_oid);                cd.first_idx = llh->llh_cat_idx;                cd.last_idx = 0;                rc = llog_process(cat_llh, llog_cat_process_cb, &d, &cd);                if (rc != 0)                        RETURN(rc);                cd.first_idx = 0;                cd.last_idx = cat_llh->lgh_last_idx;                rc = llog_process(cat_llh, llog_cat_process_cb, &d, &cd);        } else {                rc = llog_process(cat_llh, llog_cat_process_cb, &d, NULL);        }        RETURN(rc);}EXPORT_SYMBOL(llog_cat_process);static int llog_cat_reverse_process_cb(struct llog_handle *cat_llh,                                       struct llog_rec_hdr *rec, void *data){        struct llog_process_data *d = data;        struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;        struct llog_handle *llh;        int rc;        if (le32_to_cpu(rec->lrh_type) != LLOG_LOGID_MAGIC) {                CERROR("invalid record in catalog\n");                RETURN(-EINVAL);        }        CDEBUG(D_HA, "processing log "LPX64":%x at index %u of catalog "               LPX64"\n", lir->lid_id.lgl_oid, lir->lid_id.lgl_ogen,               le32_to_cpu(rec->lrh_index), cat_llh->lgh_id.lgl_oid);        rc = llog_cat_id2handle(cat_llh, &llh, &lir->lid_id);        if (rc) {                CERROR("Cannot find handle for log "LPX64"\n",                       lir->lid_id.lgl_oid);                RETURN(rc);        }        rc = llog_reverse_process(llh, d->lpd_cb, d->lpd_data, NULL);        RETURN(rc);}int llog_cat_reverse_process(struct llog_handle *cat_llh,                             llog_cb_t cb, void *data){        struct llog_process_data d;        struct llog_process_cat_data cd;        struct llog_log_hdr *llh = cat_llh->lgh_hdr;        int rc;        ENTRY;        LASSERT(llh->llh_flags & LLOG_F_IS_CAT);        d.lpd_data = data;        d.lpd_cb = cb;        if (llh->llh_cat_idx > cat_llh->lgh_last_idx) {                CWARN("catalog "LPX64" crosses index zero\n",                      cat_llh->lgh_id.lgl_oid);                cd.first_idx = 0;                cd.last_idx = cat_llh->lgh_last_idx;                rc = llog_reverse_process(cat_llh, llog_cat_reverse_process_cb,                                          &d, &cd);                if (rc != 0)                        RETURN(rc);                cd.first_idx = le32_to_cpu(llh->llh_cat_idx);                cd.last_idx = 0;                rc = llog_reverse_process(cat_llh, llog_cat_reverse_process_cb,                                          &d, &cd);        } else {                rc = llog_reverse_process(cat_llh, llog_cat_reverse_process_cb,                                          &d, NULL);        }        RETURN(rc);}EXPORT_SYMBOL(llog_cat_reverse_process);int llog_cat_set_first_idx(struct llog_handle *cathandle, int index){        struct llog_log_hdr *llh = cathandle->lgh_hdr;        int i, bitmap_size, idx;        ENTRY;        bitmap_size = LLOG_BITMAP_SIZE(llh);        if (llh->llh_cat_idx == (index - 1)) {                idx = llh->llh_cat_idx + 1;                llh->llh_cat_idx = idx;                if (idx == cathandle->lgh_last_idx)                        goto out;                for (i = (index + 1) % bitmap_size;                     i != cathandle->lgh_last_idx;                     i = (i + 1) % bitmap_size) {                        if (!ext2_test_bit(i, llh->llh_bitmap)) {                                idx = llh->llh_cat_idx + 1;                                llh->llh_cat_idx = idx;                        } else if (i == 0) {                                llh->llh_cat_idx = 0;                        } else {                                break;                        }                }out:                CDEBUG(D_RPCTRACE, "set catlog "LPX64" first idx %u\n",                       cathandle->lgh_id.lgl_oid, llh->llh_cat_idx);        }        RETURN(0);}#if 0/* Assumes caller has already pushed us into the kernel context. */int llog_cat_init(struct llog_handle *cathandle, struct obd_uuid *tgtuuid){        struct llog_log_hdr *llh;        loff_t offset = 0;        int rc = 0;        ENTRY;        LASSERT(sizeof(*llh) == LLOG_CHUNK_SIZE);        down(&cathandle->lgh_lock);        llh = cathandle->lgh_hdr;        if (i_size_read(cathandle->lgh_file->f_dentry->d_inode) == 0) {                llog_write_rec(cathandle, &llh->llh_hdr, NULL, 0, NULL, 0);write_hdr:                rc = lustre_fwrite(cathandle->lgh_file, llh, LLOG_CHUNK_SIZE,                                   &offset);                if (rc != LLOG_CHUNK_SIZE) {                        CERROR("error writing catalog header: rc %d\n", rc);                        OBD_FREE(llh, sizeof(*llh));                        if (rc >= 0)                                rc = -ENOSPC;                } else                        rc = 0;        } else {                rc = lustre_fread(cathandle->lgh_file, llh, LLOG_CHUNK_SIZE,                                  &offset);                if (rc != LLOG_CHUNK_SIZE) {                        CERROR("error reading catalog header: rc %d\n", rc);                        /* Can we do much else if the header is bad? */                        goto write_hdr;                } else                        rc = 0;        }        cathandle->lgh_tgtuuid = &llh->llh_tgtuuid;        up(&cathandle->lgh_lock);        RETURN(rc);}EXPORT_SYMBOL(llog_cat_init);#endif

⌨️ 快捷键说明

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