author | Tero Marttila <terom@fixme.fi> |
Tue, 18 Nov 2008 01:55:13 +0200 | |
changeset 41 | 6abda2fa4579 |
parent 36 | 56427f22e969 |
child 48 | 8b019d191353 |
permissions | -rw-r--r-- |
31 | 1 |
|
2 |
#include "dbfs.h" |
|
3 |
#include "../lib/log.h" |
|
4 |
#include "../lib/misc.h" |
|
5 |
||
6 |
// max. size for a setattr UPDATE query |
|
7 |
#define DBFS_SETATTR_SQL_MAX 512 |
|
8 |
||
9 |
// for building the setattr UPDATE |
|
10 |
#define FIELD(to_set, flag, field, value) ((to_set) & (flag)) ? (field " = " value ", ") : "" |
|
11 |
||
12 |
void _dbfs_attr_res (const struct evsql_result_info *res, void *arg) { |
|
13 |
struct fuse_req *req = arg; |
|
14 |
struct stat st; ZINIT(st); |
|
15 |
int err = 0; |
|
16 |
||
17 |
uint32_t ino; |
|
18 |
||
19 |
// check the results |
|
20 |
if ((err = _dbfs_check_res(res, 1, 5))) |
|
21 |
SERROR(err = (err == 1 ? ENOENT : EIO)); |
|
22 |
||
23 |
// get our data |
|
24 |
if (0 |
|
25 |
|| evsql_result_uint32(res, 0, 0, &ino, 0 ) // inodes.ino |
|
26 |
) |
|
27 |
EERROR(err = EIO, "invalid db data"); |
|
28 |
||
29 |
||
36
56427f22e969
tweak debug/info output, implement dbfs_unlink with slightly improved error macros handling
Tero Marttila <terom@fixme.fi>
parents:
33
diff
changeset
|
30 |
INFO("\t[dbfs.getattr %p] -> ino=%lu, stat follows", req, (unsigned long int) ino); |
31 | 31 |
|
32 | 32 |
// inode |
33 |
st.st_ino = ino; |
|
34 |
||
31 | 35 |
// stat attrs |
36 |
if ((err = _dbfs_stat_info(&st, res, 0, 1))) |
|
37 |
goto error; |
|
38 |
||
39 |
// reply |
|
40 |
if ((err = fuse_reply_attr(req, &st, st.st_nlink ? CACHE_TIMEOUT : 0))) |
|
41 |
EERROR(err, "fuse_reply_entry"); |
|
42 |
||
43 |
error: |
|
44 |
if (err && (err = fuse_reply_err(req, err))) |
|
45 |
EWARNING(err, "fuse_reply_err"); |
|
46 |
||
47 |
// free |
|
48 |
evsql_result_free(res); |
|
49 |
} |
|
50 |
||
51 |
void dbfs_getattr (struct fuse_req *req, fuse_ino_t ino, struct fuse_file_info *fi) { |
|
52 |
struct dbfs *ctx = fuse_req_userdata(req); |
|
41
6abda2fa4579
touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
36
diff
changeset
|
53 |
struct evsql_query *query; |
31 | 54 |
int err; |
55 |
||
56 |
(void) fi; |
|
57 |
||
58 |
INFO("[dbfs.getattr %p] ino=%lu", req, ino); |
|
59 |
||
60 |
const char *sql = |
|
61 |
"SELECT" |
|
62 |
" inodes.ino, " DBFS_STAT_COLS |
|
63 |
" FROM inodes" |
|
33 | 64 |
" WHERE inodes.ino = $1::int4"; |
31 | 65 |
|
66 |
static struct evsql_query_params params = EVSQL_PARAMS(EVSQL_FMT_BINARY) { |
|
67 |
EVSQL_PARAM ( UINT32 ), |
|
68 |
||
69 |
EVSQL_PARAMS_END |
|
70 |
}; |
|
71 |
||
72 |
// build params |
|
73 |
if (0 |
|
74 |
|| evsql_param_uint32(¶ms, 0, ino) |
|
75 |
) |
|
76 |
SERROR(err = EIO); |
|
77 |
||
78 |
// query |
|
41
6abda2fa4579
touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
36
diff
changeset
|
79 |
if ((query = evsql_query_params(ctx->db, NULL, sql, ¶ms, _dbfs_attr_res, req)) == NULL) |
31 | 80 |
SERROR(err = EIO); |
81 |
||
41
6abda2fa4579
touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
36
diff
changeset
|
82 |
// handle interrupts |
6abda2fa4579
touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
36
diff
changeset
|
83 |
fuse_req_interrupt_func(req, dbfs_interrupt_query, query); |
31 | 84 |
|
85 |
// wait |
|
86 |
return; |
|
87 |
||
88 |
error: |
|
89 |
if ((err = fuse_reply_err(req, err))) |
|
90 |
EWARNING(err, "fuse_reply_err"); |
|
91 |
} |
|
92 |
||
93 |
||
94 |
void dbfs_setattr (struct fuse_req *req, fuse_ino_t ino, struct stat *attr, int to_set, struct fuse_file_info *fi) { |
|
95 |
struct dbfs *ctx = fuse_req_userdata(req); |
|
41
6abda2fa4579
touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
36
diff
changeset
|
96 |
struct evsql_query *query; |
31 | 97 |
int err; |
98 |
int ret; |
|
99 |
||
100 |
char sql_buf[DBFS_SETATTR_SQL_MAX]; |
|
101 |
||
102 |
static struct evsql_query_params params = EVSQL_PARAMS(EVSQL_FMT_BINARY) { |
|
103 |
EVSQL_PARAM ( UINT16 ), // inodes.mode |
|
104 |
EVSQL_PARAM ( UINT32 ), // inodes.uid |
|
105 |
EVSQL_PARAM ( UINT32 ), // inodes.gid |
|
106 |
EVSQL_PARAM ( UINT32 ), // data size |
|
107 |
EVSQL_PARAM ( UINT32 ), // ino |
|
108 |
||
109 |
EVSQL_PARAMS_END |
|
110 |
}; |
|
111 |
||
112 |
// log |
|
113 |
INFO("[dbfs.setattr %p] ino=%lu, fileop=%p: ", req, ino, fi && fi->fh ? (void*) fi->fh : NULL); |
|
114 |
||
115 |
if (to_set & FUSE_SET_ATTR_MODE) { |
|
116 |
// ignore the S_IFMT |
|
117 |
attr->st_mode &= 07777; |
|
118 |
||
119 |
INFO("\tmode = %08o", attr->st_mode); |
|
120 |
} |
|
121 |
||
122 |
if (to_set & FUSE_SET_ATTR_UID) |
|
123 |
INFO("\tuid = %u", attr->st_uid); |
|
124 |
||
125 |
if (to_set & FUSE_SET_ATTR_GID) |
|
126 |
INFO("\tgid = %u", attr->st_gid); |
|
127 |
||
128 |
if (to_set & FUSE_SET_ATTR_SIZE) |
|
129 |
INFO("\tsize = %lu", attr->st_size); |
|
130 |
||
131 |
if (to_set & FUSE_SET_ATTR_ATIME) |
|
132 |
INFO("\tatime = %lu", attr->st_atime); |
|
133 |
||
134 |
if (to_set & FUSE_SET_ATTR_MTIME) |
|
135 |
INFO("\tmtime = %lu", attr->st_mtime); |
|
136 |
||
137 |
// the SQL |
|
138 |
if ((ret = snprintf(sql_buf, DBFS_SETATTR_SQL_MAX, |
|
139 |
"UPDATE inodes SET" |
|
140 |
" %s%s%s%s ino = ino" |
|
141 |
" WHERE inodes.ino = $5::int4" |
|
33 | 142 |
" RETURNING inodes.ino, " DBFS_STAT_COLS, |
31 | 143 |
|
144 |
FIELD(to_set, FUSE_SET_ATTR_MODE, "mode", "$1::int2"), |
|
145 |
FIELD(to_set, FUSE_SET_ATTR_UID, "uid", "$2::int4"), |
|
146 |
FIELD(to_set, FUSE_SET_ATTR_GID, "gid", "$3::int4"), |
|
147 |
FIELD(to_set, FUSE_SET_ATTR_SIZE, "data", "lo_otruncate(data, $4::int4)") |
|
148 |
)) >= DBFS_SETATTR_SQL_MAX && (err = EIO)) |
|
149 |
ERROR("sql_buf is too small: %i", ret); |
|
150 |
||
151 |
// the params... |
|
152 |
if (0 |
|
153 |
|| ( evsql_params_clear(¶ms) ) |
|
154 |
|| ((to_set & FUSE_SET_ATTR_MODE ) && evsql_param_uint16(¶ms, 0, attr->st_mode) ) |
|
155 |
|| ((to_set & FUSE_SET_ATTR_UID ) && evsql_param_uint32(¶ms, 1, attr->st_uid) ) |
|
156 |
|| ((to_set & FUSE_SET_ATTR_GID ) && evsql_param_uint32(¶ms, 2, attr->st_gid) ) |
|
157 |
|| ((to_set & FUSE_SET_ATTR_SIZE ) && evsql_param_uint32(¶ms, 3, attr->st_size) ) |
|
158 |
|| ( evsql_param_uint32(¶ms, 4, ino) ) |
|
159 |
) |
|
160 |
SERROR(err = EIO); |
|
161 |
||
162 |
// trace the query |
|
163 |
evsql_query_debug(sql_buf, ¶ms); |
|
164 |
||
165 |
// query... we can pretend it's a getattr :) |
|
41
6abda2fa4579
touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
36
diff
changeset
|
166 |
if ((query = evsql_query_params(ctx->db, NULL, sql_buf, ¶ms, _dbfs_attr_res, req)) == NULL) |
31 | 167 |
SERROR(err = EIO); |
168 |
||
41
6abda2fa4579
touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
36
diff
changeset
|
169 |
// handle interrupts |
6abda2fa4579
touch up the Makefile, define err_t as unsigned int in error.h, and add some preliminary interrupt support, although it will always deadlock due to a bug in libfuse
Tero Marttila <terom@fixme.fi>
parents:
36
diff
changeset
|
170 |
fuse_req_interrupt_func(req, dbfs_interrupt_query, query); |
31 | 171 |
|
172 |
// wait |
|
173 |
return; |
|
174 |
||
175 |
error: |
|
176 |
if ((err = fuse_reply_err(req, err))) |
|
177 |
EWARNING(err, "fuse_reply_err"); |
|
178 |
} |