Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / ptlrpc / llog_client.c
index 8accba6..4ebd88d 100644 (file)
@@ -1,7 +1,7 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- *  Copyright (C) 2001-2003 Cluster File Systems, Inc.
+ *  Copyright (C) 2001-2004 Cluster File Systems, Inc.
  *   Author: Andreas Dilger <adilger@clusterfs.com>
  *
  *   This file is part of Lustre, http://www.lustre.org.
 #include <linux/obd_class.h>
 #include <linux/lustre_log.h>
 #include <linux/lustre_net.h>
-#include <portals/list.h>
+#include <libcfs/list.h>
 
 /* This is a callback from the llog_* functions.
  * Assumes caller has already pushed us into the kernel context. */
-static int llog_client_create(struct llog_ctxt *ctxt, struct llog_handle **res,
-                            struct llog_logid *logid, char *name)
+static int llog_client_open(struct llog_ctxt *ctxt, struct llog_handle **res,
+                            struct llog_logid *logid, char *name, int flags)
 {
         struct obd_import *imp;
         struct llogd_body req_body;
@@ -52,9 +52,7 @@ static int llog_client_create(struct llog_ctxt *ctxt, struct llog_handle **res,
         struct ptlrpc_request *req = NULL;
         int size[2] = {sizeof(req_body)};
         char *tmp[2] = {(char*) &req_body};
-        int bufcount = 1;
-        int repsize[] = {sizeof (req_body)};
-        int rc;
+        int bufcount = 1, repsize[] = {sizeof (req_body)}, rc;
         ENTRY;
 
         LASSERT(ctxt->loc_imp);
@@ -69,6 +67,7 @@ static int llog_client_create(struct llog_ctxt *ctxt, struct llog_handle **res,
         if (logid)
                 req_body.lgd_logid = *logid;
         req_body.lgd_ctxt_idx = ctxt->loc_idx - 1;
+        req_body.lgd_llh_flags = flags;
 
         if (name) {
                 size[bufcount] = strlen(name) + 1;
@@ -76,7 +75,8 @@ static int llog_client_create(struct llog_ctxt *ctxt, struct llog_handle **res,
                 bufcount++;
         }
 
-        req = ptlrpc_prep_req(imp, LLOG_ORIGIN_HANDLE_CREATE,bufcount,size,tmp);
+        req = ptlrpc_prep_req(imp, LUSTRE_LOG_VERSION, LLOG_ORIGIN_HANDLE_OPEN,
+                              bufcount, size,tmp);
         if (!req)
                 GOTO(err_free, rc = -ENOMEM);
 
@@ -85,12 +85,12 @@ static int llog_client_create(struct llog_ctxt *ctxt, struct llog_handle **res,
         if (rc)
                 GOTO(err_free, rc);
 
-       body = lustre_swab_repbuf(req, 0, sizeof(*body),
+        body = lustre_swab_repbuf(req, 0, sizeof(*body),
                                  lustre_swab_llogd_body);
-       if (body == NULL) {
+        if (body == NULL) {
                 CERROR ("Can't unpack llogd_body\n");
                 GOTO(err_free, rc =-EFAULT);
-       }
+        }
 
         handle->lgh_id = body->lgd_logid;
         handle->lgh_ctxt = ctxt;
@@ -105,6 +105,55 @@ err_free:
         goto out;
 }
 
+static int llog_client_prev_block(struct llog_handle *loghandle,
+                                  int prev_idx, void *buf, int len)
+{
+        struct obd_import *imp = loghandle->lgh_ctxt->loc_imp;
+        struct ptlrpc_request *req = NULL;
+        struct llogd_body *body;
+        void * ptr;
+        int size = sizeof(*body);
+        int repsize[2] = {sizeof (*body)};
+        int rc;
+        ENTRY;
+
+        req = ptlrpc_prep_req(imp, LUSTRE_LOG_VERSION,
+                              LLOG_ORIGIN_HANDLE_PREV_BLOCK, 1, &size, NULL);
+        if (!req)
+                GOTO(out, rc = -ENOMEM);
+
+        body = lustre_msg_buf(req->rq_reqmsg, 0, sizeof (*body));
+        body->lgd_logid = loghandle->lgh_id;
+        body->lgd_ctxt_idx = loghandle->lgh_ctxt->loc_idx - 1;
+        body->lgd_llh_flags = loghandle->lgh_hdr->llh_flags;
+        body->lgd_index = prev_idx;
+        body->lgd_len = len;
+        repsize[1] = len;
+
+        req->rq_replen = lustre_msg_size(2, repsize);
+        rc = ptlrpc_queue_wait(req);
+        if (rc)
+                GOTO(out, rc);
+
+        body = lustre_swab_repbuf(req, 0, sizeof(*body),
+                                 lustre_swab_llogd_body);
+        if (body == NULL) {
+                CERROR ("Can't unpack llogd_body\n");
+                GOTO(out, rc =-EFAULT);
+        }
+
+        ptr = lustre_msg_buf(req->rq_repmsg, 1, len);
+        if (ptr == NULL) {
+                CERROR ("Can't unpack bitmap\n");
+                GOTO(out, rc =-EFAULT);
+        }
+
+        memcpy(buf, ptr, len);
+out:
+        if (req)
+                ptlrpc_req_finished(req);
+        RETURN(rc);
+}
 
 static int llog_client_next_block(struct llog_handle *loghandle,
                                   int *cur_idx, int next_idx,
@@ -119,7 +168,8 @@ static int llog_client_next_block(struct llog_handle *loghandle,
         int rc;
         ENTRY;
 
-        req = ptlrpc_prep_req(imp, LLOG_ORIGIN_HANDLE_NEXT_BLOCK, 1,&size,NULL);
+        req = ptlrpc_prep_req(imp, LUSTRE_LOG_VERSION,
+                              LLOG_ORIGIN_HANDLE_NEXT_BLOCK, 1, &size, NULL);
         if (!req)
                 GOTO(out, rc = -ENOMEM);
 
@@ -138,18 +188,18 @@ static int llog_client_next_block(struct llog_handle *loghandle,
         if (rc)
                 GOTO(out, rc);
 
-       body = lustre_swab_repbuf(req, 0, sizeof(*body),
+        body = lustre_swab_repbuf(req, 0, sizeof(*body),
                                  lustre_swab_llogd_body);
-       if (body == NULL) {
+        if (body == NULL) {
                 CERROR ("Can't unpack llogd_body\n");
                 GOTO(out, rc =-EFAULT);
-       }
+        }
 
         ptr = lustre_msg_buf(req->rq_repmsg, 1, len);
-       if (ptr == NULL) {
+        if (ptr == NULL) {
                 CERROR ("Can't unpack bitmap\n");
                 GOTO(out, rc =-EFAULT);
-       }
+        }
 
         *cur_idx = body->lgd_saved_index;
         *cur_offset = body->lgd_cur_offset;
@@ -169,12 +219,14 @@ static int llog_client_read_header(struct llog_handle *handle)
         struct ptlrpc_request *req = NULL;
         struct llogd_body *body;
         struct llog_log_hdr *hdr;
+        struct llog_rec_hdr *llh_hdr;
         int size = sizeof(*body);
         int repsize = sizeof (*hdr);
         int rc;
         ENTRY;
 
-        req = ptlrpc_prep_req(imp, LLOG_ORIGIN_HANDLE_READ_HEADER,1,&size,NULL);
+        req = ptlrpc_prep_req(imp, LUSTRE_LOG_VERSION,
+                              LLOG_ORIGIN_HANDLE_READ_HEADER, 1, &size, NULL);
         if (!req)
                 GOTO(out, rc = -ENOMEM);
 
@@ -188,13 +240,28 @@ static int llog_client_read_header(struct llog_handle *handle)
         if (rc)
                 GOTO(out, rc);
 
-       hdr = lustre_swab_repbuf(req, 0, sizeof(*hdr), lustre_swab_llog_hdr);
-       if (hdr == NULL) {
+        hdr = lustre_swab_repbuf(req, 0, sizeof(*hdr), lustre_swab_llog_hdr);
+        if (hdr == NULL) {
                 CERROR ("Can't unpack llog_hdr\n");
                 GOTO(out, rc =-EFAULT);
        }
+
         memcpy(handle->lgh_hdr, hdr, sizeof (*hdr));
-        handle->lgh_last_idx = le32_to_cpu(handle->lgh_hdr->llh_tail.lrt_index);
+        handle->lgh_last_idx = handle->lgh_hdr->llh_tail.lrt_index;
+
+        /* sanity checks */
+        llh_hdr = &handle->lgh_hdr->llh_hdr;
+        if (llh_hdr->lrh_type != LLOG_HDR_MAGIC) {
+                CERROR("bad log header magic: %#x (expecting %#x)\n",
+                       llh_hdr->lrh_type, LLOG_HDR_MAGIC);
+                rc = -EIO;
+        } else if (llh_hdr->lrh_len != LLOG_CHUNK_SIZE) {
+                CERROR("incorrectly sized log header: %#x "
+                       "(expecting %#x)\n",
+                       llh_hdr->lrh_len, LLOG_CHUNK_SIZE);
+                CERROR("you may need to re-run lconf --write_conf.\n");
+                rc = -EIO;
+        }
 
 out:
         if (req)
@@ -211,8 +278,9 @@ static int llog_client_close(struct llog_handle *handle)
 
 
 struct llog_operations llog_client_ops = {
+        lop_prev_block:  llog_client_prev_block,
         lop_next_block:  llog_client_next_block,
         lop_read_header: llog_client_read_header,
-        lop_create:      llog_client_create,
+        lop_open:        llog_client_open,
         lop_close:       llog_client_close,
 };