1 #include "dbfs.h" |
1 #include "dbfs.h" |
2 |
2 |
|
3 /* |
|
4 * Handling simple ino-related ops, like lookup, readlink, unlink and link |
|
5 */ |
|
6 |
3 #include "../lib/log.h" |
7 #include "../lib/log.h" |
|
8 #include "../lib/misc.h" |
|
9 |
|
10 /* |
|
11 * Used for lookup and link |
|
12 */ |
|
13 void dbfs_entry_res (const struct evsql_result_info *res, void *arg) { |
|
14 struct fuse_req *req = arg; |
|
15 struct fuse_entry_param e; ZINIT(e); |
|
16 int err = 0; |
|
17 |
|
18 uint32_t ino; |
|
19 |
|
20 // check the results |
|
21 if ((err = _dbfs_check_res(res, 1, 5))) |
|
22 SERROR(err = (err == 1 ? ENOENT : EIO)); |
|
23 |
|
24 // get the data |
|
25 if (0 |
|
26 || evsql_result_uint32(res, 0, 0, &ino, 0 ) // inodes.ino |
|
27 ) |
|
28 EERROR(err = EIO, "invalid db data"); |
|
29 |
|
30 INFO("\t[dbfs.lookup] -> ino=%u", ino); |
|
31 |
|
32 // stat attrs |
|
33 if ((err = _dbfs_stat_info(&e.attr, res, 0, 1))) |
|
34 goto error; |
|
35 |
|
36 // other attrs |
|
37 e.ino = e.attr.st_ino = ino; |
|
38 e.attr_timeout = CACHE_TIMEOUT; |
|
39 e.entry_timeout = CACHE_TIMEOUT; |
|
40 |
|
41 // reply |
|
42 if ((err = fuse_reply_entry(req, &e))) |
|
43 EERROR(err, "fuse_reply_entry"); |
|
44 |
|
45 error: |
|
46 if (err && (err = fuse_reply_err(req, err))) |
|
47 EWARNING(err, "fuse_reply_err"); |
|
48 |
|
49 // free |
|
50 evsql_result_free(res); |
|
51 } |
|
52 |
|
53 void dbfs_lookup (struct fuse_req *req, fuse_ino_t parent, const char *name) { |
|
54 struct dbfs *ctx = fuse_req_userdata(req); |
|
55 int err; |
|
56 |
|
57 INFO("[dbfs.lookup] parent=%lu name=%s", parent, name); |
|
58 |
|
59 // query and params |
|
60 const char *sql = |
|
61 "SELECT" |
|
62 " inodes.ino, " DBFS_STAT_COLS |
|
63 " FROM file_tree INNER JOIN inodes ON (file_tree.ino = inodes.ino)" |
|
64 " WHERE file_tree.parent = $1::int4 AND file_tree.name = $2::varchar"; |
|
65 |
|
66 static struct evsql_query_params params = EVSQL_PARAMS(EVSQL_FMT_BINARY) { |
|
67 EVSQL_PARAM ( UINT32 ), |
|
68 EVSQL_PARAM ( STRING ), |
|
69 |
|
70 EVSQL_PARAMS_END |
|
71 }; |
|
72 |
|
73 // build params |
|
74 if (0 |
|
75 || evsql_param_uint32(¶ms, 0, parent) |
|
76 || evsql_param_string(¶ms, 1, name) |
|
77 ) |
|
78 EERROR(err = EIO, "evsql_param_*"); |
|
79 |
|
80 // query |
|
81 if (evsql_query_params(ctx->db, NULL, sql, ¶ms, dbfs_entry_res, req) == NULL) |
|
82 EERROR(err = EIO, "evsql_query_params"); |
|
83 |
|
84 // XXX: handle interrupts |
|
85 |
|
86 // wait |
|
87 return; |
|
88 |
|
89 error: |
|
90 if ((err = fuse_reply_err(req, err))) |
|
91 EWARNING(err, "fuse_reply_err"); |
|
92 } |
4 |
93 |
5 void _dbfs_readlink_res (const struct evsql_result_info *res, void *arg) { |
94 void _dbfs_readlink_res (const struct evsql_result_info *res, void *arg) { |
6 struct fuse_req *req = arg; |
95 struct fuse_req *req = arg; |
7 int err = 0; |
96 int err = 0; |
8 |
97 |
140 error: |
229 error: |
141 if ((err = fuse_reply_err(req, err))) |
230 if ((err = fuse_reply_err(req, err))) |
142 EWARNING(err, "fuse_reply_err"); |
231 EWARNING(err, "fuse_reply_err"); |
143 } |
232 } |
144 |
233 |
|
234 void dbfs_link (struct fuse_req *req, fuse_ino_t ino, fuse_ino_t newparent, const char *newname) { |
|
235 struct dbfs *ctx = fuse_req_userdata(req); |
|
236 int err; |
|
237 |
|
238 INFO("[dbfs.link %p] ino=%lu, newparent=%lu, newname=%s", req, ino, newparent, newname); |
|
239 |
|
240 const char *sql = |
|
241 "SELECT ino, type, mode, size, nlink FROM dbfs_link($1::int4, $2::int4, $3::varchar)"; |
|
242 |
|
243 static struct evsql_query_params params = EVSQL_PARAMS(EVSQL_FMT_BINARY) { |
|
244 EVSQL_PARAM ( UINT32 ), |
|
245 EVSQL_PARAM ( UINT32 ), |
|
246 EVSQL_PARAM ( STRING ), |
|
247 |
|
248 EVSQL_PARAMS_END |
|
249 }; |
|
250 |
|
251 // build params |
|
252 if (0 |
|
253 || evsql_param_uint32(¶ms, 0, ino) |
|
254 || evsql_param_uint32(¶ms, 1, newparent) |
|
255 || evsql_param_string(¶ms, 2, newname) |
|
256 ) |
|
257 SERROR(err = EIO); |
|
258 |
|
259 // query |
|
260 if (evsql_query_params(ctx->db, NULL, sql, ¶ms, dbfs_entry_res, req) == NULL) |
|
261 SERROR(err = EIO); |
|
262 |
|
263 // XXX: handle interrupts |
|
264 |
|
265 // wait |
|
266 return; |
|
267 |
|
268 error: |
|
269 if ((err = fuse_reply_err(req, err))) |
|
270 EWARNING(err, "fuse_reply_err"); |
|
271 } |