Whamcloud - gitweb
7415316bce923059599ddd08af4dbc0dcf7138e9
[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 smfs_super_info *smb)
34 {
35         struct dentry *dentry = NULL;
36         int rc = 0;
37
38         /* create OBJECTS and LOGS for writing logs */
39         ENTRY;
40
41         //push_ctxt(&saved, S2SMI(sb)->smsi_ctxt, NULL);
42         dentry = simple_mkdir(current->fs->pwd, "LOGS", 0777, 1);
43         if (IS_ERR(dentry)) {
44                 rc = PTR_ERR(dentry);
45                 CERROR("cannot create LOGS directory: rc = %d\n", rc);
46                 rc = -EINVAL;
47                 goto exit;
48         }
49
50         smb->smsi_logs_dir = dentry;
51                 
52         dentry = simple_mkdir(current->fs->pwd, "OBJECTS", 0777, 1);
53         if (IS_ERR(dentry)) {
54                 rc = PTR_ERR(dentry);
55                 CERROR("cannot create OBJECTS directory: rc = %d\n", rc);
56                 rc = -EINVAL;
57                 goto exit;
58         }
59
60         smb->smsi_objects_dir = dentry;
61         
62 exit:
63         RETURN(rc);
64 }
65
66 int smfs_llog_cleanup(struct smfs_super_info *smb)
67 {
68         ENTRY;
69
70         /*
71         if (SMFS_CACHE_HOOK(S2SMI(sb)))
72                 rc = cache_space_hook_cleanup();
73
74         if (SMFS_DO_REC(S2SMI(sb))) {
75                 rc2 = llog_catalog_cleanup(ctxt);
76                 OBD_FREE(ctxt, sizeof(*ctxt));
77                 if (!rc)
78                         rc = rc2;
79         }
80         */
81         if (smb->smsi_logs_dir) {
82                 l_dput(smb->smsi_logs_dir);
83                 smb->smsi_logs_dir = NULL;
84         }
85         if (smb->smsi_objects_dir) {
86                 l_dput(smb->smsi_objects_dir);
87                 smb->smsi_objects_dir = NULL;
88         }
89         RETURN(0);
90 }
91
92 int smfs_llog_add_rec(struct smfs_super_info *smb, void *data, int data_size)
93 {
94         struct llog_rec_hdr rec;
95         int rc = 0;
96         
97         ENTRY;
98         rec.lrh_len = size_round(data_size);
99         rec.lrh_type = SMFS_UPDATE_REC;
100
101         rc = llog_catalog_add(smb->smsi_kml_log, &rec, data, NULL, 0, NULL, NULL, NULL);
102         if (rc != 1) {
103                 CERROR("error adding kml rec: %d\n", rc);
104                 RETURN(-EINVAL);
105         }
106         RETURN(0);
107 }
108