Whamcloud - gitweb
LU-1346 libcfs: cleanup macros in kp30.h
[fs/lustre-release.git] / lustre / obdclass / llog_lvfs.c
index 1debe27..a83cb6f 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2012, Intel Corporation.
+ * Copyright (c) 2012, 2013, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -272,9 +272,9 @@ static int llog_lvfs_write_rec(const struct lu_env *env,
                         /* We assume that caller has set lgh_cur_* */
                         saved_offset = loghandle->lgh_cur_offset;
                         CDEBUG(D_OTHER,
-                               "modify record "LPX64": idx:%d/%u/%d, len:%u "
+                               "modify record "DOSTID": idx:%d/%u/%d, len:%u "
                                "offset %llu\n",
-                               loghandle->lgh_id.lgl_oid, idx, rec->lrh_index,
+                               POSTID(&loghandle->lgh_id.lgl_oi), idx, rec->lrh_index,
                                loghandle->lgh_cur_idx, rec->lrh_len,
                                (long long)(saved_offset - sizeof(*llh)));
                         if (rec->lrh_index != loghandle->lgh_cur_idx) {
@@ -348,8 +348,8 @@ static int llog_lvfs_write_rec(const struct lu_env *env,
         if (rc)
                 RETURN(rc);
 
-        CDEBUG(D_RPCTRACE, "added record "LPX64": idx: %u, %u \n",
-               loghandle->lgh_id.lgl_oid, index, rec->lrh_len);
+       CDEBUG(D_RPCTRACE, "added record "DOSTID": idx: %u, %u \n",
+              POSTID(&loghandle->lgh_id.lgl_oi), index, rec->lrh_len);
         if (rc == 0 && reccookie) {
                 reccookie->lgc_lgl = loghandle->lgh_id;
                 reccookie->lgc_index = index;
@@ -417,13 +417,13 @@ static int llog_lvfs_next_block(const struct lu_env *env,
                                        loghandle->lgh_file, buf, llen,
                                        cur_offset);
                if (rc < 0) {
-                        CERROR("Cant read llog block at log id "LPU64
-                               "/%u offset "LPU64"\n",
-                               loghandle->lgh_id.lgl_oid,
-                               loghandle->lgh_id.lgl_ogen,
-                               *cur_offset);
-                        RETURN(rc);
-                }
+                       CERROR("Cant read llog block at log id "DOSTID
+                              "/%u offset "LPU64"\n",
+                              POSTID(&loghandle->lgh_id.lgl_oi),
+                              loghandle->lgh_id.lgl_ogen,
+                              *cur_offset);
+                       RETURN(rc);
+               }
 
                 /* put number of bytes read into rc to make code simpler */
                rc = *cur_offset - ppos;
@@ -435,12 +435,12 @@ static int llog_lvfs_next_block(const struct lu_env *env,
                 if (rc == 0) /* end of file, nothing to do */
                         RETURN(0);
 
-                if (rc < sizeof(*tail)) {
-                        CERROR("Invalid llog block at log id "LPU64"/%u offset "
-                               LPU64"\n", loghandle->lgh_id.lgl_oid,
-                               loghandle->lgh_id.lgl_ogen, *cur_offset);
-                        RETURN(-EINVAL);
-                }
+               if (rc < sizeof(*tail)) {
+                       CERROR("Invalid llog block at log id "DOSTID"/%u offset"
+                              LPU64"\n", POSTID(&loghandle->lgh_id.lgl_oi),
+                              loghandle->lgh_id.lgl_ogen, *cur_offset);
+                       RETURN(-EINVAL);
+               }
 
                 rec = buf;
                if (LLOG_REC_HDR_NEEDS_SWABBING(rec))
@@ -459,13 +459,13 @@ static int llog_lvfs_next_block(const struct lu_env *env,
 
                 *cur_idx = tail->lrt_index;
 
-                /* this shouldn't happen */
-                if (tail->lrt_index == 0) {
-                        CERROR("Invalid llog tail at log id "LPU64"/%u offset "
-                               LPU64"\n", loghandle->lgh_id.lgl_oid,
-                               loghandle->lgh_id.lgl_ogen, *cur_offset);
-                        RETURN(-EINVAL);
-                }
+               /* this shouldn't happen */
+               if (tail->lrt_index == 0) {
+                       CERROR("Invalid llog tail at log id "DOSTID"/%u offset "
+                              LPU64"\n", POSTID(&loghandle->lgh_id.lgl_oi),
+                              loghandle->lgh_id.lgl_ogen, *cur_offset);
+                       RETURN(-EINVAL);
+               }
                 if (tail->lrt_index < next_idx)
                         continue;
 
@@ -506,13 +506,13 @@ static int llog_lvfs_prev_block(const struct lu_env *env,
                                        loghandle->lgh_file, buf, len,
                                        &cur_offset);
                if (rc < 0) {
-                        CERROR("Cant read llog block at log id "LPU64
-                               "/%u offset "LPU64"\n",
-                               loghandle->lgh_id.lgl_oid,
-                               loghandle->lgh_id.lgl_ogen,
-                               cur_offset);
-                        RETURN(rc);
-                }
+                       CERROR("Cant read llog block at log id "DOSTID
+                              "/%u offset "LPU64"\n",
+                              POSTID(&loghandle->lgh_id.lgl_oi),
+                              loghandle->lgh_id.lgl_ogen,
+                              cur_offset);
+                       RETURN(rc);
+               }
 
                 /* put number of bytes read into rc to make code simpler */
                rc = cur_offset - ppos;
@@ -521,8 +521,8 @@ static int llog_lvfs_prev_block(const struct lu_env *env,
                         RETURN(0);
 
                 if (rc < sizeof(*tail)) {
-                        CERROR("Invalid llog block at log id "LPU64"/%u offset "
-                               LPU64"\n", loghandle->lgh_id.lgl_oid,
+                        CERROR("Invalid llog block at log id "DOSTID"/%u offset"
+                               LPU64"\n", POSTID(&loghandle->lgh_id.lgl_oi),
                                loghandle->lgh_id.lgl_ogen, cur_offset);
                         RETURN(-EINVAL);
                 }
@@ -542,13 +542,13 @@ static int llog_lvfs_prev_block(const struct lu_env *env,
                        lustre_swab_llog_rec(last_rec);
                LASSERT(last_rec->lrh_index == tail->lrt_index);
 
-                /* this shouldn't happen */
-                if (tail->lrt_index == 0) {
-                        CERROR("Invalid llog tail at log id "LPU64"/%u offset "
-                               LPU64"\n", loghandle->lgh_id.lgl_oid,
-                               loghandle->lgh_id.lgl_ogen, cur_offset);
-                        RETURN(-EINVAL);
-                }
+               /* this shouldn't happen */
+               if (tail->lrt_index == 0) {
+                       CERROR("Invalid llog tail at log id "DOSTID"/%u offset"
+                              LPU64"\n", POSTID(&loghandle->lgh_id.lgl_oi),
+                              loghandle->lgh_id.lgl_ogen, cur_offset);
+                       RETURN(-EINVAL);
+               }
                if (tail->lrt_index < prev_idx)
                         continue;
 
@@ -605,35 +605,32 @@ static int llog_lvfs_open(const struct lu_env *env,  struct llog_handle *handle,
 
        LASSERT(handle);
        if (logid != NULL) {
-               dchild = obd_lvfs_fid2dentry(ctxt->loc_exp, logid->lgl_oid,
-                                            logid->lgl_ogen, logid->lgl_oseq);
+               dchild = obd_lvfs_fid2dentry(ctxt->loc_exp, &logid->lgl_oi,
+                                            logid->lgl_ogen);
                if (IS_ERR(dchild)) {
                        rc = PTR_ERR(dchild);
-                       CERROR("%s: error looking up logfile #"LPX64"#"
-                              LPX64"#%08x: rc = %d\n",
-                              ctxt->loc_obd->obd_name, logid->lgl_oid,
-                              logid->lgl_oseq, logid->lgl_ogen, rc);
+                       CERROR("%s: error looking up logfile #"DOSTID "#%08x:"
+                              " rc = %d\n", ctxt->loc_obd->obd_name,
+                              POSTID(&logid->lgl_oi), logid->lgl_ogen, rc);
                        GOTO(out, rc);
                }
                if (dchild->d_inode == NULL) {
                        l_dput(dchild);
                        rc = -ENOENT;
-                       CERROR("%s: nonexistent llog #"LPX64"#"LPX64"#%08x: "
+                       CERROR("%s: nonexistent llog #"DOSTID"#%08x:"
                               "rc = %d\n", ctxt->loc_obd->obd_name,
-                              logid->lgl_oid, logid->lgl_oseq,
-                              logid->lgl_ogen, rc);
+                              POSTID(&logid->lgl_oi), logid->lgl_ogen, rc);
                        GOTO(out, rc);
                }
-               /* l_dentry_open will call dput(dchild) if there is an error */
                handle->lgh_file = l_dentry_open(&obd->obd_lvfs_ctxt, dchild,
                                                 O_RDWR | O_LARGEFILE);
+               l_dput(dchild);
                if (IS_ERR(handle->lgh_file)) {
                        rc = PTR_ERR(handle->lgh_file);
                        handle->lgh_file = NULL;
-                       CERROR("%s: error opening llog #"LPX64"#"LPX64"#%08x: "
+                       CERROR("%s: error opening llog #"DOSTID"#%08x:"
                               "rc = %d\n", ctxt->loc_obd->obd_name,
-                              logid->lgl_oid, logid->lgl_oseq,
-                              logid->lgl_ogen, rc);
+                              POSTID(&logid->lgl_oi), logid->lgl_ogen, rc);
                        GOTO(out, rc);
                }
                handle->lgh_id = *logid;
@@ -654,11 +651,9 @@ static int llog_lvfs_open(const struct lu_env *env,  struct llog_handle *handle,
                                GOTO(out, rc);
                        }
                } else {
-                       handle->lgh_id.lgl_oseq = FID_SEQ_LLOG;
-                       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;
+                       lustre_build_llog_lvfs_oid(&handle->lgh_id,
+                           handle->lgh_file->f_dentry->d_inode->i_ino,
+                           handle->lgh_file->f_dentry->d_inode->i_generation);
                }
        } else {
                LASSERTF(open_param == LLOG_OPEN_NEW, "%#x\n", open_param);
@@ -709,17 +704,16 @@ static int llog_lvfs_create(const struct lu_env *env,
                if (IS_ERR(file))
                        RETURN(PTR_ERR(file));
 
-               handle->lgh_id.lgl_oseq = FID_SEQ_LLOG;
-               handle->lgh_id.lgl_oid = file->f_dentry->d_inode->i_ino;
-               handle->lgh_id.lgl_ogen =
-                               file->f_dentry->d_inode->i_generation;
+               lustre_build_llog_lvfs_oid(&handle->lgh_id,
+                               file->f_dentry->d_inode->i_ino,
+                               file->f_dentry->d_inode->i_generation);
                handle->lgh_file = file;
        } else {
                OBDO_ALLOC(oa);
                if (oa == NULL)
                        RETURN(-ENOMEM);
 
-               oa->o_seq = FID_SEQ_LLOG;
+               ostid_set_seq_llog(&oa->o_oi);
                oa->o_valid = OBD_MD_FLGENER | OBD_MD_FLGROUP;
 
                rc = obd_create(NULL, ctxt->loc_exp, oa, NULL, NULL);
@@ -730,16 +724,16 @@ static int llog_lvfs_create(const struct lu_env *env,
                 *        this API along with mds_obd_{create,destroy}.
                 *        Hopefully it is only an internal API issue. */
 #define o_generation o_parent_oid
-               dchild = obd_lvfs_fid2dentry(ctxt->loc_exp, oa->o_id,
-                                            oa->o_generation, oa->o_seq);
+               dchild = obd_lvfs_fid2dentry(ctxt->loc_exp, &oa->o_oi,
+                                            oa->o_generation);
                if (IS_ERR(dchild))
                        GOTO(out, rc = PTR_ERR(dchild));
 
                file = l_dentry_open(&obd->obd_lvfs_ctxt, dchild, open_flags);
+               l_dput(dchild);
                if (IS_ERR(file))
                        GOTO(out, rc = PTR_ERR(file));
-               handle->lgh_id.lgl_oseq = oa->o_seq;
-               handle->lgh_id.lgl_oid = oa->o_id;
+               handle->lgh_id.lgl_oi = oa->o_oi;
                handle->lgh_id.lgl_ogen = oa->o_generation;
                handle->lgh_file = file;
 out:
@@ -759,9 +753,9 @@ static int llog_lvfs_close(const struct lu_env *env,
                RETURN(0);
        rc = filp_close(handle->lgh_file, 0);
        if (rc)
-               CERROR("%s: error closing llog #"LPX64"#"LPX64"#%08x: "
+               CERROR("%s: error closing llog #"DOSTID"#%08x: "
                       "rc = %d\n", handle->lgh_ctxt->loc_obd->obd_name,
-                      handle->lgh_id.lgl_oid, handle->lgh_id.lgl_oseq,
+                      POSTID(&handle->lgh_id.lgl_oi),
                       handle->lgh_id.lgl_ogen, rc);
        handle->lgh_file = NULL;
        if (handle->lgh_name) {
@@ -811,9 +805,8 @@ static int llog_lvfs_destroy(const struct lu_env *env,
         if (oa == NULL)
                 RETURN(-ENOMEM);
 
-        oa->o_id = handle->lgh_id.lgl_oid;
-        oa->o_seq = handle->lgh_id.lgl_oseq;
-        oa->o_generation = handle->lgh_id.lgl_ogen;
+       oa->o_oi = handle->lgh_id.lgl_oi;
+       oa->o_generation = handle->lgh_id.lgl_ogen;
 #undef o_generation
         oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP | OBD_MD_FLGENER;
 
@@ -838,107 +831,6 @@ static int llog_lvfs_destroy(const struct lu_env *env,
         RETURN(rc);
 }
 
-/* reads the catalog list */
-int llog_get_cat_list(struct obd_device *disk_obd,
-                      char *name, int idx, int count, struct llog_catid *idarray)
-{
-        struct lvfs_run_ctxt saved;
-        struct l_file *file;
-        int rc, rc1 = 0;
-        int size = sizeof(*idarray) * count;
-        loff_t off = idx *  sizeof(*idarray);
-        ENTRY;
-
-        if (!count)
-                RETURN(0);
-
-        push_ctxt(&saved, &disk_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);
-
-        /* read for new ost index or for empty file */
-        memset(idarray, 0, size);
-        if (i_size_read(file->f_dentry->d_inode) < off)
-                GOTO(out, rc = 0);
-
-        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, &disk_obd->obd_lvfs_ctxt, NULL);
-        if (file && !IS_ERR(file))
-                rc1 = filp_close(file, 0);
-        if (rc == 0)
-                rc = rc1;
-        return rc;
-}
-EXPORT_SYMBOL(llog_get_cat_list);
-
-/* writes the cat list */
-int llog_put_cat_list(struct obd_device *disk_obd,
-                      char *name, int idx, int count, struct llog_catid *idarray)
-{
-        struct lvfs_run_ctxt saved;
-        struct l_file *file;
-        int rc, rc1 = 0;
-        int size = sizeof(*idarray) * count;
-        loff_t off = idx * sizeof(*idarray);
-
-        if (!count)
-                GOTO(out1, rc = 0);
-
-        push_ctxt(&saved, &disk_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 writeing %s: rc %d\n",
-                       name, rc);
-                GOTO(out, rc);
-        }
-
-out:
-        pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);
-        if (file && !IS_ERR(file))
-                rc1 = filp_close(file, 0);
-
-        if (rc == 0)
-                rc = rc1;
-out1:
-        RETURN(rc);
-}
-EXPORT_SYMBOL(llog_put_cat_list);
-
 static int llog_lvfs_declare_create(const struct lu_env *env,
                                    struct llog_handle *res,
                                    struct thandle *th)
@@ -969,21 +861,5 @@ struct llog_operations llog_lvfs_ops = {
 };
 EXPORT_SYMBOL(llog_lvfs_ops);
 #else /* !__KERNEL__ */
-int llog_get_cat_list(struct obd_device *disk_obd,
-                     char *name, int idx, int count,
-                     struct llog_catid *idarray)
-{
-       LBUG();
-       return 0;
-}
-
-int llog_put_cat_list(struct obd_device *disk_obd,
-                     char *name, int idx, int count,
-                     struct llog_catid *idarray)
-{
-       LBUG();
-       return 0;
-}
-
 struct llog_operations llog_lvfs_ops = {};
 #endif