Whamcloud - gitweb
- landed b_hd_mdref (mostly WB cache fixes)
[fs/lustre-release.git] / lustre / smfs / smfs_llog.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  lustre/smfs/smfs_llog.c
5  *  Lustre filesystem abstraction routines
6  *
7  *  Copyright (C) 2004 Cluster File Systems, Inc.
8  *
9  *   This file is part of Lustre, http://www.lustre.org.
10  *
11  *   Lustre is free software; you can redistribute it and/or
12  *   modify it under the terms of version 2 of the GNU General Public
13  *   License as published by the Free Software Foundation.
14  *
15  *   Lustre is distributed in the hope that it will be useful,
16  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *   GNU General Public License for more details.
19  *
20  *   You should have received a copy of the GNU General Public License
21  *   along with Lustre; if not, write to the Free Software
22  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24
25 #define DEBUG_SUBSYSTEM S_SM
26
27 #include <linux/lustre_log.h>
28 #include <linux/lustre_fsfilt.h>
29 #include <linux/lustre_smfs.h>
30 #include <linux/lvfs.h>
31
32 #include "smfs_internal.h"
33 int smfs_llog_setup(struct dentry **logs, struct dentry **objects)
34 {
35         struct dentry *dentry = NULL;
36         int rc = 0;
37         ENTRY;
38
39         /* create OBJECTS and LOGS for writing logs */
40         dentry = simple_mkdir(current->fs->pwd, "LOGS", 0777, 1);
41         if (IS_ERR(dentry)) {
42                 CERROR("cannot create LOGS directory: rc = %d\n",
43                        (int)PTR_ERR(dentry));
44                 RETURN(rc);
45         }
46         *logs = dentry;
47         
48         dentry = simple_mkdir(current->fs->pwd, "OBJECTS", 0777, 1);
49         if (IS_ERR(dentry)) {
50                 CERROR("cannot create OBJECTS directory: rc = %d\n",
51                        (int)PTR_ERR(dentry));
52                 RETURN(rc);
53         }
54         *objects = dentry;
55         
56         RETURN(rc);
57 }
58
59 int smfs_llog_cleanup(struct smfs_super_info *smb)
60 {
61         ENTRY;
62
63         /*
64         if (SMFS_CACHE_HOOK(S2SMI(sb)))
65                 rc = cache_space_hook_cleanup();
66
67         if (SMFS_DO_REC(S2SMI(sb))) {
68                 rc2 = llog_catalog_cleanup(ctxt);
69                 OBD_FREE(ctxt, sizeof(*ctxt));
70                 if (!rc)
71                         rc = rc2;
72         }
73         */
74         if (smb->smsi_logs_dir) {
75                 l_dput(smb->smsi_logs_dir);
76                 smb->smsi_logs_dir = NULL;
77         }
78         if (smb->smsi_objects_dir) {
79                 l_dput(smb->smsi_objects_dir);
80                 smb->smsi_objects_dir = NULL;
81         }
82         RETURN(0);
83 }
84
85 int smfs_llog_add_rec(struct smfs_super_info *smb, void *data, int data_size)
86 {
87         struct llog_rec_hdr rec;
88         int rc = 0;
89         
90         ENTRY;
91         rec.lrh_len = size_round(data_size);
92         rec.lrh_type = SMFS_UPDATE_REC;
93
94         rc = llog_catalog_add(smb->smsi_kml_log, &rec, data, NULL, 0, NULL, NULL, NULL);
95         if (rc != 1) {
96                 CERROR("error adding kml rec: %d\n", rc);
97                 RETURN(-EINVAL);
98         }
99         RETURN(0);
100 }
101