Whamcloud - gitweb
Branch: HEAD
[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 super_block *sb, struct vfsmount *mnt)
34 {
35         struct dentry *dentry = NULL;
36         int rc = 0;
37
38         /* create OBJECTS and LOGS for writing logs */
39         ENTRY;
40
41         LASSERT(mnt);
42
43         //push_ctxt(&saved, S2SMI(sb)->smsi_ctxt, NULL);
44         dentry = simple_mkdir(current->fs->pwd, "LOGS", 0777, 1);
45         if (IS_ERR(dentry)) {
46                 rc = PTR_ERR(dentry);
47                 CERROR("cannot create LOGS directory: rc = %d\n", rc);
48                 rc = -EINVAL;
49                 goto exit;
50         }
51
52         S2SMI(sb)->smsi_logs_dir = dentry;
53         //SMFS_SET(I2SMI(dentry->d_inode)->smi_flags, SMFS_PLG_ALL);
54         
55         dentry = simple_mkdir(current->fs->pwd, "OBJECTS", 0777, 1);
56         if (IS_ERR(dentry)) {
57                 rc = PTR_ERR(dentry);
58                 CERROR("cannot create OBJECTS directory: rc = %d\n", rc);
59                 rc = -EINVAL;
60                 goto exit;
61         }
62
63         S2SMI(sb)->smsi_objects_dir = dentry;
64         //SMFS_SET(I2SMI(dentry->d_inode)->smi_flags, SMFS_PLG_ALL);
65
66         /* write log will not write to KML, cleanup kml flags */
67         //SMFS_CLEAN_INODE_REC(S2SMI(sb)->smsi_objects_dir->d_inode);
68         //SMFS_CLEAN_INODE_REC(S2SMI(sb)->smsi_logs_dir->d_inode);
69
70         /* log create does not call cache hooks, cleanup hook flags */
71         //SMFS_CLEAN_INODE_CACHE_HOOK(S2SMI(sb)->smsi_objects_dir->d_inode);
72         //SMFS_CLEAN_INODE_CACHE_HOOK(S2SMI(sb)->smsi_logs_dir->d_inode);
73
74         
75         /*if (SMFS_CACHE_HOOK(S2SMI(sb))) {
76                 rc2 = cache_space_hook_setup(sb);
77                 if (!rc && rc2)
78                         rc = rc2;
79         }*/
80 exit:
81         //pop_ctxt(&saved, S2SMI(sb)->smsi_ctxt, NULL);
82         RETURN(rc);
83 }
84
85 int smfs_llog_cleanup(struct super_block *sb)
86 {
87         ENTRY;
88
89         /*
90         if (SMFS_CACHE_HOOK(S2SMI(sb)))
91                 rc = cache_space_hook_cleanup();
92
93         if (SMFS_DO_REC(S2SMI(sb))) {
94                 rc2 = llog_catalog_cleanup(ctxt);
95                 OBD_FREE(ctxt, sizeof(*ctxt));
96                 if (!rc)
97                         rc = rc2;
98         }
99         */
100         if (S2SMI(sb)->smsi_logs_dir) {
101                 l_dput(S2SMI(sb)->smsi_logs_dir);
102                 S2SMI(sb)->smsi_logs_dir = NULL;
103         }
104         if (S2SMI(sb)->smsi_objects_dir) {
105                 l_dput(S2SMI(sb)->smsi_objects_dir);
106                 S2SMI(sb)->smsi_objects_dir = NULL;
107         }
108         RETURN(0);
109 }
110
111 int smfs_llog_add_rec(struct smfs_super_info *sinfo, void *data, int data_size)
112 {
113         struct llog_rec_hdr rec;
114         int rc = 0;
115
116         rec.lrh_len = size_round(data_size);
117         rec.lrh_type = SMFS_UPDATE_REC;
118
119         rc = llog_add(sinfo->smsi_kml_log, &rec, data, NULL, 0, NULL, NULL, NULL);
120         if (rc != 1) {
121                 CERROR("error adding kml rec: %d\n", rc);
122                 RETURN(-EINVAL);
123         }
124         RETURN(0);
125 }
126