From: <uj...@us...> - 2009-03-27 04:25:17
|
Revision: 4136 http://gfarm.svn.sourceforge.net/gfarm/?rev=4136&view=rev Author: ujihara Date: 2009-03-27 04:24:57 +0000 (Fri, 27 Mar 2009) Log Message: ----------- testing Trac#48 (xattr giant_lock) still testing, especially for gffindxmlattr next commit will be on Monday fix dbq with callback delete unnecessary functions fix LDAP binary handling fix typo etc. Modified Paths: -------------- gfarm_v2/trunk/gftool/config-gfarm/gfarm.schema gfarm_v2/trunk/lib/libgfarm/gfarm/gfm_proto.h gfarm_v2/trunk/server/gfmd/db_access.c gfarm_v2/trunk/server/gfmd/db_access.h gfarm_v2/trunk/server/gfmd/db_ldap.c gfarm_v2/trunk/server/gfmd/db_none.c gfarm_v2/trunk/server/gfmd/db_ops.h gfarm_v2/trunk/server/gfmd/db_pgsql.c gfarm_v2/trunk/server/gfmd/inode.c gfarm_v2/trunk/server/gfmd/inode.h gfarm_v2/trunk/server/gfmd/xattr.c Modified: gfarm_v2/trunk/gftool/config-gfarm/gfarm.schema =================================================================== --- gfarm_v2/trunk/gftool/config-gfarm/gfarm.schema 2009-03-26 14:22:07 UTC (rev 4135) +++ gfarm_v2/trunk/gftool/config-gfarm/gfarm.schema 2009-03-27 04:24:57 UTC (rev 4136) @@ -108,8 +108,7 @@ EQUALITY caseExactMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE ) attributetype ( 1.3.6.1.4.1.13122.2.1.2924.101.2.30 NAME 'attrvalue' - EQUALITY caseExactMatch - SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE ) + SYNTAX 1.3.6.1.4.1.1466.115.121.1.5 SINGLE-VALUE ) # Object Class Definitions # 1.3.6.1.4.1.13122.2.1.2924.101.3.x Modified: gfarm_v2/trunk/lib/libgfarm/gfarm/gfm_proto.h =================================================================== --- gfarm_v2/trunk/lib/libgfarm/gfarm/gfm_proto.h 2009-03-26 14:22:07 UTC (rev 4135) +++ gfarm_v2/trunk/lib/libgfarm/gfarm/gfm_proto.h 2009-03-27 04:24:57 UTC (rev 4136) @@ -289,7 +289,7 @@ GFJ_PROTO_RESERVE14, GFJ_PROTO_RESERVE15, - /* extended attribude management */ + /* extended attribute management */ GFM_PROTO_XATTR_SET, GFM_PROTO_XMLATTR_SET, GFM_PROTO_XATTR_GET, Modified: gfarm_v2/trunk/server/gfmd/db_access.c =================================================================== --- gfarm_v2/trunk/server/gfmd/db_access.c 2009-03-26 14:22:07 UTC (rev 4135) +++ gfarm_v2/trunk/server/gfmd/db_access.c 2009-03-27 04:24:57 UTC (rev 4136) @@ -19,18 +19,21 @@ #define ALIGNMENT 8 #define ALIGN(offset) (((offset) + ALIGNMENT - 1) & ~(ALIGNMENT - 1)) -typedef void (*dbq_entry_func_t)(void *); -typedef gfarm_error_t (*dbq_entry_func_witherr_t)(void *); +typedef gfarm_error_t (*dbq_entry_func_t)(void *); typedef void (*dbq_entry_func_callback_t)(gfarm_error_t, void *); -struct dbq_entry { +struct dbq_callback_arg { dbq_entry_func_t func; void *data; - dbq_entry_func_witherr_t funcwitherr; - dbq_entry_func_callback_t callback; + dbq_entry_func_callback_t cbfunc; void *cbdata; }; +struct dbq_entry { + dbq_entry_func_t func; + void *data; +}; + #define DBQ_SIZE 1000 struct dbq { @@ -90,9 +93,7 @@ } static gfarm_error_t -dbq_enter_common(struct dbq *q, dbq_entry_func_t func, - void *data, dbq_entry_func_witherr_t func_witherr, - dbq_entry_func_callback_t func_callback, void *callbackdata) +dbq_enter(struct dbq *q, dbq_entry_func_t func, void *data) { int err; gfarm_error_t e; @@ -122,9 +123,6 @@ } q->entries[q->in].func = func; q->entries[q->in].data = data; - q->entries[q->in].funcwitherr = func_witherr; - q->entries[q->in].callback = func_callback; - q->entries[q->in].cbdata = callbackdata; q->in++; if (q->in >= DBQ_SIZE) q->in = 0; @@ -140,19 +138,38 @@ return (e); } -gfarm_error_t -dbq_enter(struct dbq *q, dbq_entry_func_t func, void *data) +static gfarm_error_t +dbq_call_callback(void *a) { - return dbq_enter_common(q, func, data, NULL, NULL, NULL); + gfarm_error_t e; + struct dbq_callback_arg *arg = (struct dbq_callback_arg *)a; + + e = (*arg->func)(arg->data); + if (arg->cbfunc != NULL) { + (*arg->cbfunc)(e, arg->cbdata); + } + free(arg); + return e; } static gfarm_error_t dbq_enter_withcallback(struct dbq *q, - dbq_entry_func_witherr_t func_witherr, void *data, - dbq_entry_func_callback_t func_callback, void *callbackdata) + dbq_entry_func_t func, void *data, + dbq_entry_func_callback_t cbfunc, void *cbdata) { - return dbq_enter_common(q, NULL, data, - func_witherr, func_callback, callbackdata); + gfarm_error_t e; + struct dbq_callback_arg *arg = GFARM_MALLOC(arg); + + if (arg == NULL) + return GFARM_ERR_NO_MEMORY; + arg->func = func; + arg->data = data; + arg->cbfunc = cbfunc; + arg->cbdata = cbdata; + e = dbq_enter(q, dbq_call_callback, arg); + if (e != GFARM_ERR_NO_ERROR) + free(arg); + return e; } #define UNINITIALIZED_GFARM_ERROR (-1) @@ -217,10 +234,9 @@ static gfarm_error_t dbq_enter_for_waitret(struct dbq *q, - dbq_entry_func_witherr_t func_witherr, void *data, - struct db_waitctx *ctx) + dbq_entry_func_t func, void *data, struct db_waitctx *ctx) { - return dbq_enter_withcallback(q, func_witherr, data, + return dbq_enter_withcallback(q, func, data, dbq_done_callback, ctx); } @@ -315,14 +331,9 @@ for (;;) { e = dbq_delete(&dbq, &ent); - if (e == GFARM_ERR_NO_ERROR) - if (ent.func != NULL) - (*ent.func)(ent.data); - else { - e = (*ent.funcwitherr)(ent.data); - (*ent.callback)(e, ent.cbdata); - } - else if (e == GFARM_ERR_NO_SUCH_OBJECT) + if (e == GFARM_ERR_NO_ERROR) { + (*ent.func)(ent.data); + } else if (e == GFARM_ERR_NO_SUCH_OBJECT) break; } @@ -1106,7 +1117,7 @@ * Same as db_xattr_modify(). */ e = dbq_enter_for_waitret(&dbq, - (dbq_entry_func_witherr_t)ops->xattr_add, arg, waitctx); + (dbq_entry_func_t)ops->xattr_add, arg, waitctx); } else e = dbq_enter(&dbq, (dbq_entry_func_t)ops->xattr_add, arg); @@ -1128,7 +1139,7 @@ arg->size = size; if (waitctx != NULL) e = dbq_enter_for_waitret(&dbq, - (dbq_entry_func_witherr_t)ops->xattr_modify, arg, waitctx); + (dbq_entry_func_t)ops->xattr_modify, arg, waitctx); else e = dbq_enter(&dbq, (dbq_entry_func_t)ops->xattr_modify, arg); @@ -1149,26 +1160,25 @@ } gfarm_error_t -db_xattr_get(int xmlMode, gfarm_ino_t inum, char *attrname, - void **valuep, size_t *sizep, struct db_waitctx *waitctx) +db_xattr_removeall(int xmlMode, gfarm_ino_t inum) { - struct db_xattr_arg *arg = db_xattr_arg_alloc(attrname, 0); - if (arg == NULL) - return GFARM_ERR_NO_ERROR; - arg->xmlMode = xmlMode; - arg->inum = inum; - arg->valuep = valuep; - arg->sizep = sizep; - return dbq_enter_for_waitret(&dbq, - (dbq_entry_func_witherr_t)ops->xattr_get, arg, waitctx); + if (ops->xattr_removeall != NULL) { + struct db_xattr_arg *arg = db_xattr_arg_alloc(NULL, 0); + if (arg == NULL) + return GFARM_ERR_NO_ERROR; + arg->xmlMode = xmlMode; + arg->inum = inum; + return dbq_enter(&dbq, + (dbq_entry_func_t)ops->xattr_removeall, arg); + } else + return GFARM_ERR_OPERATION_NOT_SUPPORTED; } gfarm_error_t -db_xattr_list(int xmlMode, gfarm_ino_t inum, void **valuep, size_t *sizep, - struct db_waitctx *waitctx) +db_xattr_get(int xmlMode, gfarm_ino_t inum, char *attrname, + void **valuep, size_t *sizep, struct db_waitctx *waitctx) { - struct db_xattr_arg *arg = db_xattr_arg_alloc(NULL, 0); - + struct db_xattr_arg *arg = db_xattr_arg_alloc(attrname, 0); if (arg == NULL) return GFARM_ERR_NO_ERROR; arg->xmlMode = xmlMode; @@ -1176,7 +1186,7 @@ arg->valuep = valuep; arg->sizep = sizep; return dbq_enter_for_waitret(&dbq, - (dbq_entry_func_witherr_t)ops->xattr_list, arg, waitctx); + (dbq_entry_func_t)ops->xattr_get, arg, waitctx); } gfarm_error_t @@ -1202,6 +1212,6 @@ arg->foundcallback = foundcallback; arg->foundcbdata = foundcbdata; return dbq_enter_withcallback(&dbq, - (dbq_entry_func_witherr_t)ops->xmlattr_find, arg, + (dbq_entry_func_t)ops->xmlattr_find, arg, (dbq_entry_func_callback_t)callback, cbdata); } Modified: gfarm_v2/trunk/server/gfmd/db_access.h =================================================================== --- gfarm_v2/trunk/server/gfmd/db_access.h 2009-03-26 14:22:07 UTC (rev 4135) +++ gfarm_v2/trunk/server/gfmd/db_access.h 2009-03-27 04:24:57 UTC (rev 4136) @@ -91,10 +91,9 @@ gfarm_error_t db_xattr_modify(int, gfarm_ino_t, char *, void *, size_t, struct db_waitctx *); gfarm_error_t db_xattr_remove(int, gfarm_ino_t, char *); +gfarm_error_t db_xattr_removeall(int, gfarm_ino_t); gfarm_error_t db_xattr_get(int, gfarm_ino_t, char *, void **, size_t *, struct db_waitctx *); -gfarm_error_t db_xattr_list(int, gfarm_ino_t, void **, size_t *, - struct db_waitctx *); gfarm_error_t db_xattr_load(void *closure, void (*callback)(void *, struct xattr_info *)); gfarm_error_t db_xmlattr_find(gfarm_ino_t, const char *, Modified: gfarm_v2/trunk/server/gfmd/db_ldap.c =================================================================== --- gfarm_v2/trunk/server/gfmd/db_ldap.c 2009-03-26 14:22:07 UTC (rev 4135) +++ gfarm_v2/trunk/server/gfmd/db_ldap.c 2009-03-27 04:24:57 UTC (rev 4136) @@ -544,73 +544,29 @@ *modp = &storage->mod; } -static char * -binary2hextext(const void *data, int size) -{ - char *chdata; - int chlen; - char *src, *dst, *last; +struct ldap_binary_modify { + LDAPMod mod; + struct berval *val[2]; + struct berval v; +}; - chlen = (size > 0) ? 2 * size + 1 : 2; - GFARM_MALLOC_ARRAY(chdata, chlen); - if (chdata == NULL) - return NULL; - - if (size > 0) { - src = (char *)data; - dst = chdata; - last = (src + size); - while (src < last) { - sprintf(dst, "%02hhx", *src); - src += sizeof(*src); - dst += 2 * sizeof(*dst); - } - *dst = '\0'; - } else { - /* - * NOTE: OpenLDAP denies zero length text. - * Use "0" as empty text. - */ - chdata[0] = '0'; - chdata[1] = '\0'; - } - - return chdata; -} - -static void * -hextext2binary(char *chdata, int *size) +static void +set_binary_mod( + LDAPMod **modp, + int op, + char *type, + void *value, + int size, + struct ldap_binary_modify *storage) { - char *data; - int chlen = strlen(chdata); - int allocsize; - char *src, *dst, *last, v[3]; - - if (chlen >= 2) - allocsize = *size = chlen / 2; - else { - // empty data - *size = 0; - chlen = 0; - allocsize = 1; // malloc(0) may returns NULL or !NULL - } - GFARM_MALLOC_ARRAY(data, allocsize); - if (data == NULL) - return NULL; - - src = chdata; - dst = data; - last = (src + chlen); - v[2] = '\0'; - while (src < last) { - v[0] = *src; - v[1] = *(src + 1); - *dst = strtol(v, NULL, 16); - src += 2 * sizeof(*src); - dst += sizeof(*dst); - } - - return data; + storage->v.bv_val = value; + storage->v.bv_len = size; + storage->val[0] = &storage->v; + storage->val[1] = NULL; + storage->mod.mod_op = op | LDAP_MOD_BVALUES; + storage->mod.mod_type = type; + storage->mod.mod_vals.modv_bvals = storage->val; + *modp = &storage->mod; } static void @@ -1152,33 +1108,39 @@ return ((*update_op)(&key, modv, &gfarm_ldap_host_info_ops)); } -static void +static gfarm_error_t gfarm_ldap_host_add(struct gfarm_host_info *info) { - gfarm_ldap_host_info_update(info, + gfarm_error_t e; + e = gfarm_ldap_host_info_update(info, LDAP_MOD_ADD, gfarm_ldap_generic_info_add); free(info); + return e; } -static void +static gfarm_error_t gfarm_ldap_host_modify(struct db_host_modify_arg *arg) { + gfarm_error_t e; /* XXX FIXME: should use modflags, add_aliases and del_aliases */ - gfarm_ldap_host_info_update(&arg->hi, + e = gfarm_ldap_host_info_update(&arg->hi, LDAP_MOD_REPLACE, gfarm_ldap_generic_info_modify); free(arg); + return e; } -static void +static gfarm_error_t gfarm_ldap_host_remove(char *hostname) { + gfarm_error_t e; struct gfarm_ldap_host_info_key key; key.hostname = hostname; - gfarm_ldap_generic_info_remove(&key, &gfarm_ldap_host_info_ops); + e = gfarm_ldap_generic_info_remove(&key, &gfarm_ldap_host_info_ops); free(hostname); + return e; } static gfarm_error_t @@ -1297,31 +1259,37 @@ return ((*update_op)(&key, modv, &gfarm_ldap_user_info_ops)); } -static void +static gfarm_error_t gfarm_ldap_user_add(struct gfarm_user_info *info) { - gfarm_ldap_user_info_update(info, + gfarm_error_t e; + e = gfarm_ldap_user_info_update(info, LDAP_MOD_ADD, gfarm_ldap_generic_info_add); free(info); + return e; } -static void +static gfarm_error_t gfarm_ldap_user_modify(struct db_user_modify_arg *arg) { - gfarm_ldap_user_info_update(&arg->ui, + gfarm_error_t e; + e = gfarm_ldap_user_info_update(&arg->ui, LDAP_MOD_REPLACE, gfarm_ldap_generic_info_modify); free(arg); + return e; } -static void +static gfarm_error_t gfarm_ldap_user_remove(char *username) { + gfarm_error_t e; struct gfarm_ldap_user_info_key key; key.username = username; - gfarm_ldap_generic_info_remove(&key, &gfarm_ldap_user_info_ops); + e = gfarm_ldap_generic_info_remove(&key, &gfarm_ldap_user_info_ops); free(username); + return e; } static gfarm_error_t @@ -1426,31 +1394,37 @@ return ((*update_op)(&key, modv, &gfarm_ldap_group_info_ops)); } -static void +static gfarm_error_t gfarm_ldap_group_add(struct gfarm_group_info *info) { - gfarm_ldap_group_info_update(info, + gfarm_error_t e; + e = gfarm_ldap_group_info_update(info, LDAP_MOD_ADD, gfarm_ldap_generic_info_add); free(info); + return e; } -static void +static gfarm_error_t gfarm_ldap_group_modify(struct db_group_modify_arg *arg) { - gfarm_ldap_group_info_update(&arg->gi, + gfarm_error_t e; + e = gfarm_ldap_group_info_update(&arg->gi, LDAP_MOD_REPLACE, gfarm_ldap_generic_info_modify); free(arg); + return e; } -static void +static gfarm_error_t gfarm_ldap_group_remove(char *groupname) { + gfarm_error_t e; struct gfarm_ldap_group_info_key key; key.groupname = groupname; - gfarm_ldap_generic_info_remove(&key, &gfarm_ldap_group_info_ops); + e = gfarm_ldap_generic_info_remove(&key, &gfarm_ldap_group_info_ops); free(groupname); + return e; } static gfarm_error_t @@ -1624,20 +1598,24 @@ return ((*update_op)(&key, modv, &gfarm_ldap_gfs_stat_ops)); } -static void +static gfarm_error_t gfarm_ldap_inode_add(struct gfs_stat *info) { - gfarm_ldap_gfs_stat_update(info, + gfarm_error_t e; + e = gfarm_ldap_gfs_stat_update(info, LDAP_MOD_ADD, gfarm_ldap_generic_info_add); free(info); + return e; } -static void +static gfarm_error_t gfarm_ldap_inode_modify(struct gfs_stat *info) { - gfarm_ldap_gfs_stat_update(info, + gfarm_error_t e; + e = gfarm_ldap_gfs_stat_update(info, LDAP_MOD_REPLACE, gfarm_ldap_generic_info_modify); free(info); + return e; } static gfarm_error_t @@ -1743,19 +1721,19 @@ return (e); } -static void +static gfarm_error_t gfarm_ldap_inode_nlink_modify(struct db_inode_uint64_modify_arg *arg) { - ldap_inode_uint64_modify(arg, "nlink"); + return ldap_inode_uint64_modify(arg, "nlink"); } -static void +static gfarm_error_t gfarm_ldap_inode_size_modify(struct db_inode_uint64_modify_arg *arg) { - ldap_inode_uint64_modify(arg, "size"); + return ldap_inode_uint64_modify(arg, "size"); } -static void +static gfarm_error_t gfarm_ldap_inode_mode_modify(struct db_inode_uint32_modify_arg *arg) { gfarm_error_t e; @@ -1785,36 +1763,37 @@ &gfarm_ldap_gfs_stat_ops); free(arg); + return e; } -static void +static gfarm_error_t gfarm_ldap_inode_user_modify(struct db_inode_string_modify_arg *arg) { - ldap_inode_string_modify(arg, "username"); + return ldap_inode_string_modify(arg, "username"); } -static void +static gfarm_error_t gfarm_ldap_inode_group_modify(struct db_inode_string_modify_arg *arg) { - ldap_inode_string_modify(arg, "groupname"); + return ldap_inode_string_modify(arg, "groupname"); } -static void +static gfarm_error_t gfarm_ldap_inode_atime_modify(struct db_inode_timespec_modify_arg *arg) { - ldap_inode_timespec_modify(arg, "atimesec", "atimensec"); + return ldap_inode_timespec_modify(arg, "atimesec", "atimensec"); } -static void +static gfarm_error_t gfarm_ldap_inode_mtime_modify(struct db_inode_timespec_modify_arg *arg) { - ldap_inode_timespec_modify(arg, "mtimesec", "mtimensec"); + return ldap_inode_timespec_modify(arg, "mtimesec", "mtimensec"); } -static void +static gfarm_error_t gfarm_ldap_inode_ctime_modify(struct db_inode_timespec_modify_arg *arg) { - ldap_inode_timespec_modify(arg, "ctimesec", "ctimensec"); + return ldap_inode_timespec_modify(arg, "ctimesec", "ctimensec"); } @@ -1891,23 +1870,27 @@ return ((*update_op)(&key, modv, &gfarm_ldap_inode_cksum_ops)); } -static void +static gfarm_error_t gfarm_ldap_inode_cksum_add(struct db_inode_cksum_arg *arg) { - gfarm_ldap_inode_cksum_update(arg, + gfarm_error_t e; + e = gfarm_ldap_inode_cksum_update(arg, LDAP_MOD_ADD, gfarm_ldap_generic_info_modify); free(arg); + return e; } -static void +static gfarm_error_t gfarm_ldap_inode_cksum_modify(struct db_inode_cksum_arg *arg) { - gfarm_ldap_inode_cksum_update(arg, + gfarm_error_t e; + e = gfarm_ldap_inode_cksum_update(arg, LDAP_MOD_REPLACE, gfarm_ldap_generic_info_modify); free(arg); + return e; } -static void +static gfarm_error_t gfarm_ldap_inode_cksum_remove(struct db_inode_inum_arg *arg) { gfarm_error_t e; @@ -1927,6 +1910,7 @@ &gfarm_ldap_inode_cksum_ops); free(arg); + return e; } static gfarm_error_t @@ -2022,19 +2006,23 @@ return ((*update_op)(info, modv, &gfarm_ldap_db_filecopy_ops)); } -static void +static gfarm_error_t gfarm_ldap_filecopy_add(struct db_filecopy_arg *info) { - gfarm_ldap_db_filecopy_update(info, + gfarm_error_t e; + e = gfarm_ldap_db_filecopy_update(info, LDAP_MOD_ADD, gfarm_ldap_generic_info_add); free(info); + return e; } -static void +static gfarm_error_t gfarm_ldap_filecopy_remove(struct db_filecopy_arg *arg) { - gfarm_ldap_generic_info_remove(arg, &gfarm_ldap_db_filecopy_ops); + gfarm_error_t e; + e = gfarm_ldap_generic_info_remove(arg, &gfarm_ldap_db_filecopy_ops); free(arg); + return e; } static gfarm_error_t @@ -2141,19 +2129,23 @@ return ((*update_op)(info, modv, &gfarm_ldap_db_deadfilecopy_ops)); } -static void +static gfarm_error_t gfarm_ldap_deadfilecopy_add(struct db_deadfilecopy_arg *info) { - gfarm_ldap_db_deadfilecopy_update(info, + gfarm_error_t e; + e = gfarm_ldap_db_deadfilecopy_update(info, LDAP_MOD_ADD, gfarm_ldap_generic_info_add); free(info); + return e; } -static void +static gfarm_error_t gfarm_ldap_deadfilecopy_remove(struct db_deadfilecopy_arg *arg) { - gfarm_ldap_generic_info_remove(arg, &gfarm_ldap_db_deadfilecopy_ops); + gfarm_error_t e; + e = gfarm_ldap_generic_info_remove(arg, &gfarm_ldap_db_deadfilecopy_ops); free(arg); + return e; } static gfarm_error_t @@ -2317,19 +2309,23 @@ return ((*update_op)(&key, modv, &gfarm_ldap_db_direntry_ops)); } -static void +static gfarm_error_t gfarm_ldap_direntry_add(struct db_direntry_arg *info) { - gfarm_ldap_db_direntry_update(info, + gfarm_error_t e; + e = gfarm_ldap_db_direntry_update(info, LDAP_MOD_ADD, gfarm_ldap_generic_info_add); free(info); + return e; } -static void +static gfarm_error_t gfarm_ldap_direntry_remove(struct db_direntry_arg *arg) { - gfarm_ldap_generic_info_remove(arg, &gfarm_ldap_db_direntry_ops); + gfarm_error_t e; + e = gfarm_ldap_generic_info_remove(arg, &gfarm_ldap_db_direntry_ops); free(arg); + return e; } static gfarm_error_t @@ -2413,19 +2409,23 @@ return ((*update_op)(&key, modv, &gfarm_ldap_db_symlink_ops)); } -static void +static gfarm_error_t gfarm_ldap_symlink_add(struct db_symlink_arg *info) { - gfarm_ldap_db_symlink_update(info, + gfarm_error_t e; + e = gfarm_ldap_db_symlink_update(info, LDAP_MOD_ADD, gfarm_ldap_generic_info_add); free(info); + return e; } -static void +static gfarm_error_t gfarm_ldap_symlink_remove(struct db_inode_inum_arg *arg) { - gfarm_ldap_generic_info_remove(arg, &gfarm_ldap_db_symlink_ops); + gfarm_error_t e; + e = gfarm_ldap_generic_info_remove(arg, &gfarm_ldap_db_symlink_ops); free(arg); + return e; } static gfarm_error_t @@ -2471,8 +2471,8 @@ char *dn; GFARM_MALLOC_ARRAY(dn, strlen(gfarm_ldap_xattr_info_ops.dn_template) + - strlen(key->attrname) + INT64STRLEN - + strlen(gfarm_ldap_base_dn) + 1); + strlen(key->attrname) + INT64STRLEN + + strlen(gfarm_ldap_base_dn) + 1); if (dn == NULL) return (NULL); sprintf(dn, gfarm_ldap_xattr_info_ops.dn_template, @@ -2504,17 +2504,13 @@ int i; LDAPMod *modv[5]; struct ldap_string_modify storage[ARRAY_LENGTH(modv) - 1]; + struct ldap_binary_modify binstorage; char ino_string[INT64STRLEN + 1]; struct gfarm_ldap_xattr_get_info_key key; - char *hextext; if (arg->xmlMode) return GFARM_ERR_OPERATION_NOT_SUPPORTED; - hextext = binary2hextext(arg->value, arg->size); - if (hextext == NULL) - return GFARM_ERR_NO_MEMORY; - key.inumber = arg->inum; key.attrname = arg->attrname; @@ -2530,14 +2526,13 @@ set_string_mod(&modv[i], mod_op, "attrname", (char *)arg->attrname, &storage[i]); i++; - set_string_mod(&modv[i], mod_op, - "attrvalue", hextext, &storage[i]); + set_binary_mod(&modv[i], mod_op, + "attrvalue", (void *)arg->value, arg->size, &binstorage); i++; modv[i++] = NULL; assert(i == ARRAY_LENGTH(modv)); e = ((*update_op)(&key, modv, &gfarm_ldap_xattr_info_ops)); - free(hextext); return e; } @@ -2582,13 +2577,13 @@ gfarm_ldap_xattr_get(struct db_xattr_arg *arg) { gfarm_error_t e; - int rv, cnt, sz; char *query_type; char *attrs[2] = { "attrvalue", NULL }; struct timeval tout = { 10, 0 }; + int cnt, rv; LDAPMessage *res = NULL, *m; struct berval **vals; - void *bindata; + void *p; if (arg->xmlMode) { e = GFARM_ERR_OPERATION_NOT_SUPPORTED; @@ -2602,8 +2597,8 @@ } sprintf(query_type, - "(&(objectclass=XAttr)(inumber=%" GFARM_PRId64 ")(attrname=%s))", - arg->inum, arg->attrname); + "(&(objectclass=XAttr)(inumber=%" GFARM_PRId64 ")(attrname=%s))", + arg->inum, arg->attrname); rv = ldap_search_st(gfarm_ldap_server, gfarm_ldap_base_dn, LDAP_SCOPE_SUB, query_type, attrs, 0, &tout, &res); free(query_type); @@ -2626,17 +2621,20 @@ m = ldap_first_message(gfarm_ldap_server, res); vals = ldap_get_values_len(gfarm_ldap_server, m, attrs[0]); if ((vals[0] != NULL) && (vals[1] == NULL)) { - bindata = hextext2binary(vals[0]->bv_val, &sz); - if (bindata != NULL) { - *arg->valuep = bindata; - *arg->sizep = sz; - e = GFARM_ERR_NO_ERROR; - } else { - e = GFARM_ERR_NO_MEMORY; - } - } else { + e = GFARM_ERR_NO_ERROR; + *arg->sizep = vals[0]->bv_len; + if (vals[0]->bv_len > 0) { + p = malloc(vals[0]->bv_len); + if (p != NULL) { + memcpy(p, vals[0]->bv_val, + vals[0]->bv_len); + *arg->valuep = p; + } else + e = GFARM_ERR_NO_MEMORY; + } else + *arg->valuep = NULL; + } else e = GFARM_ERR_UNKNOWN; - } ldap_value_free_len(vals); } ldap_msgfree(res); @@ -2649,9 +2647,13 @@ gfarm_ldap_xattr_load(void *closure, void (*callback)(void *, struct xattr_info *)) { + int xmlMode = (closure != NULL) ? *(int*)closure : 0; struct xattr_info tmp_info; char *attrs[] = { "inumber", "attrname", NULL }; + if (xmlMode) + return GFARM_ERR_OPERATION_NOT_SUPPORTED; + /* * NOTE: Without attrs, attrvalue will be loaded also. * It's needless for initial loading. @@ -2659,93 +2661,11 @@ return (gfarm_ldap_generic_info_get_foreach_withattrs( gfarm_ldap_base_dn, LDAP_SCOPE_SUBTREE, gfarm_ldap_xattr_info_ops.query_type, - &tmp_info, (void (*)(void *, void *))callback, closure, + &tmp_info, (void (*)(void *, void *))callback, &xmlMode, &gfarm_ldap_xattr_info_ops, attrs)); } static gfarm_error_t -gfarm_ldap_xattr_list(struct db_xattr_arg *arg) -{ - gfarm_error_t e = GFARM_ERR_NO_ERROR; - int rv; - char query_type[64]; - char *attrs[2] = { "attrname", NULL }; - struct timeval tout = { 10, 0 }; - LDAPMessage *res = NULL, *m; - struct berval **vals; - int i; - char *value, *p; - int size = 0; - - *arg->sizep = 0; - *arg->valuep = NULL; - - if (arg->xmlMode) { - e = GFARM_ERR_OPERATION_NOT_SUPPORTED; - goto quit; - } - - snprintf(query_type, sizeof(query_type), - "(&(objectclass=XAttr)(inumber=%" GFARM_PRId64 "))", - arg->inum); - rv = ldap_search_st(gfarm_ldap_server, gfarm_ldap_base_dn, - LDAP_SCOPE_SUB, query_type, attrs, 0, &tout, &res); - if (rv == LDAP_NO_SUCH_OBJECT) - e = GFARM_ERR_NO_SUCH_OBJECT; - else if (rv != LDAP_SUCCESS) - e = GFARM_ERR_UNKNOWN; - else if (ldap_count_messages(gfarm_ldap_server, res) <= 1) - e = GFARM_ERR_NO_SUCH_OBJECT; - if (e != GFARM_ERR_NO_ERROR) { - ldap_msgfree(res); - goto quit; - } - - m = ldap_first_message(gfarm_ldap_server, res); - while (m != NULL) { - vals = ldap_get_values_len(gfarm_ldap_server, m, attrs[0]); - i = 0; - while (vals[i] != NULL) { - size += vals[i]->bv_len + 1; // +1 for '\0' - i++; - } - ldap_value_free_len(vals); - m = ldap_next_entry(gfarm_ldap_server, m); - } - - GFARM_MALLOC_ARRAY(value, size); - if (value == NULL) { - ldap_msgfree(res); - e = GFARM_ERR_NO_MEMORY; - goto quit; - } - - p = value; - m = ldap_first_message(gfarm_ldap_server, res); - while (m != NULL) { - vals = ldap_get_values_len(gfarm_ldap_server, m, attrs[0]); - i = 0; - while (vals[i] != NULL) { - memcpy(p, vals[i]->bv_val, vals[i]->bv_len); - p += vals[i]->bv_len; - *p = '\0'; - p++; - i++; - } - ldap_value_free_len(vals); - m = ldap_next_entry(gfarm_ldap_server, m); - } - - ldap_msgfree(res); - - *arg->sizep = size; - *arg->valuep = value; -quit: - free(arg); - return GFARM_ERR_NO_ERROR; -} - -static gfarm_error_t gfarm_ldap_xmlattr_find(struct db_xmlattr_find_arg *arg) { free(arg); @@ -2811,8 +2731,8 @@ gfarm_ldap_xattr_add, gfarm_ldap_xattr_modify, gfarm_ldap_xattr_remove, + NULL, // gfarm_ldap_xattr_removeall not supported gfarm_ldap_xattr_get, - gfarm_ldap_xattr_list, gfarm_ldap_xattr_load, gfarm_ldap_xmlattr_find, }; Modified: gfarm_v2/trunk/server/gfmd/db_none.c =================================================================== --- gfarm_v2/trunk/server/gfmd/db_none.c 2009-03-26 14:22:07 UTC (rev 4135) +++ gfarm_v2/trunk/server/gfmd/db_none.c 2009-03-27 04:24:57 UTC (rev 4136) @@ -44,22 +44,25 @@ /**********************************************************************/ -static void +static gfarm_error_t gfarm_none_host_add(struct gfarm_host_info *info) { free(info); + return (GFARM_ERR_OPERATION_NOT_SUPPORTED); } -static void +static gfarm_error_t gfarm_none_host_modify(struct db_host_modify_arg *arg) { free(arg); + return (GFARM_ERR_OPERATION_NOT_SUPPORTED); } -static void +static gfarm_error_t gfarm_none_host_remove(char *hostname) { free(hostname); + return (GFARM_ERR_OPERATION_NOT_SUPPORTED); } static gfarm_error_t @@ -71,22 +74,25 @@ /**********************************************************************/ -static void +static gfarm_error_t gfarm_none_user_add(struct gfarm_user_info *info) { free(info); + return (GFARM_ERR_OPERATION_NOT_SUPPORTED); } -static void +static gfarm_error_t gfarm_none_user_modify(struct db_user_modify_arg *arg) { free(arg); + return (GFARM_ERR_OPERATION_NOT_SUPPORTED); } -static void +static gfarm_error_t gfarm_none_user_remove(char *username) { free(username); + return (GFARM_ERR_OPERATION_NOT_SUPPORTED); } static gfarm_error_t @@ -98,22 +104,25 @@ /**********************************************************************/ -static void +static gfarm_error_t gfarm_none_group_add(struct gfarm_group_info *info) { free(info); + return (GFARM_ERR_OPERATION_NOT_SUPPORTED); } -static void +static gfarm_error_t gfarm_none_group_modify(struct db_group_modify_arg *arg) { free(arg); + return (GFARM_ERR_OPERATION_NOT_SUPPORTED); } -static void +static gfarm_error_t gfarm_none_group_remove(char *groupname) { free(groupname); + return (GFARM_ERR_OPERATION_NOT_SUPPORTED); } static gfarm_error_t @@ -125,28 +134,39 @@ /**********************************************************************/ -static void +static gfarm_error_t +gfarm_none_inode_stat_free(struct gfs_stat *arg) +{ + gfs_stat_free(arg); + return (GFARM_ERR_OPERATION_NOT_SUPPORTED); +} + +static gfarm_error_t gfarm_none_inode_int64_free(struct db_inode_uint64_modify_arg *arg) { free(arg); + return (GFARM_ERR_OPERATION_NOT_SUPPORTED); } -static void +static gfarm_error_t gfarm_none_inode_int32_free(struct db_inode_uint32_modify_arg *arg) { free(arg); + return (GFARM_ERR_OPERATION_NOT_SUPPORTED); } -static void +static gfarm_error_t gfarm_none_inode_string_free(struct db_inode_string_modify_arg *arg) { free(arg); + return (GFARM_ERR_OPERATION_NOT_SUPPORTED); } -static void +static gfarm_error_t gfarm_none_inode_timespec_free(struct db_inode_timespec_modify_arg *arg) { free(arg); + return (GFARM_ERR_OPERATION_NOT_SUPPORTED); } static gfarm_error_t @@ -159,16 +179,18 @@ /**********************************************************************/ -static void +static gfarm_error_t gfarm_none_inode_cksum_free(struct db_inode_cksum_arg *arg) { free(arg); + return (GFARM_ERR_OPERATION_NOT_SUPPORTED); } -static void +static gfarm_error_t gfarm_none_inode_inum_free(struct db_inode_inum_arg *arg) { free(arg); + return (GFARM_ERR_OPERATION_NOT_SUPPORTED); } static gfarm_error_t @@ -181,10 +203,11 @@ /**********************************************************************/ -static void +static gfarm_error_t gfarm_none_filecopy_free(struct db_filecopy_arg *arg) { free(arg); + return (GFARM_ERR_OPERATION_NOT_SUPPORTED); } static gfarm_error_t @@ -197,10 +220,11 @@ /**********************************************************************/ -static void +static gfarm_error_t gfarm_none_deadfilecopy_free(struct db_deadfilecopy_arg *arg) { free(arg); + return (GFARM_ERR_OPERATION_NOT_SUPPORTED); } static gfarm_error_t @@ -213,16 +237,18 @@ /**********************************************************************/ -static void +static gfarm_error_t gfarm_none_direntry_add(struct db_direntry_arg *arg) { free(arg); + return (GFARM_ERR_OPERATION_NOT_SUPPORTED); } -static void +static gfarm_error_t gfarm_none_direntry_remove(struct db_direntry_arg *arg) { free(arg); + return (GFARM_ERR_OPERATION_NOT_SUPPORTED); } static gfarm_error_t @@ -235,10 +261,11 @@ /**********************************************************************/ -static void +static gfarm_error_t gfarm_none_symlink_free(struct db_symlink_arg *arg) { free(arg); + return (GFARM_ERR_OPERATION_NOT_SUPPORTED); } static gfarm_error_t @@ -279,13 +306,6 @@ return (GFARM_ERR_OPERATION_NOT_SUPPORTED); } -static gfarm_error_t -gfarm_none_xattr_list(struct db_xattr_arg *arg) -{ - free(arg); - return (GFARM_ERR_OPERATION_NOT_SUPPORTED); -} - gfarm_error_t gfarm_none_xattr_load(void *closure, void (*callback)(void *, struct xattr_info *)) @@ -321,8 +341,8 @@ gfarm_none_group_remove, gfarm_none_group_load, - gfs_stat_free, - gfs_stat_free, + gfarm_none_inode_stat_free, + gfarm_none_inode_stat_free, gfarm_none_inode_int64_free, gfarm_none_inode_int64_free, gfarm_none_inode_int32_free, @@ -359,8 +379,8 @@ gfarm_none_xattr_add, gfarm_none_xattr_modify, gfarm_none_xattr_remove, + NULL, // gfarm_none_xattr_removeall not supported gfarm_none_xattr_get, - gfarm_none_xattr_list, gfarm_none_xattr_load, gfarm_none_xmlattr_find, }; Modified: gfarm_v2/trunk/server/gfmd/db_ops.h =================================================================== --- gfarm_v2/trunk/server/gfmd/db_ops.h 2009-03-26 14:22:07 UTC (rev 4135) +++ gfarm_v2/trunk/server/gfmd/db_ops.h 2009-03-27 04:24:57 UTC (rev 4136) @@ -115,70 +115,70 @@ gfarm_error_t (*initialize)(void); gfarm_error_t (*terminate)(void); - void (*host_add)(struct gfarm_host_info *); - void (*host_modify)(struct db_host_modify_arg *); - void (*host_remove)(char *); + gfarm_error_t (*host_add)(struct gfarm_host_info *); + gfarm_error_t (*host_modify)(struct db_host_modify_arg *); + gfarm_error_t (*host_remove)(char *); gfarm_error_t (*host_load)(void *, void (*)(void *, struct gfarm_host_info *)); - void (*user_add)(struct gfarm_user_info *); - void (*user_modify)(struct db_user_modify_arg *); - void (*user_remove)(char *); + gfarm_error_t (*user_add)(struct gfarm_user_info *); + gfarm_error_t (*user_modify)(struct db_user_modify_arg *); + gfarm_error_t (*user_remove)(char *); gfarm_error_t (*user_load)(void *, void (*)(void *, struct gfarm_user_info *)); - void (*group_add)(struct gfarm_group_info *); - void (*group_modify)(struct db_group_modify_arg *); - void (*group_remove)(char *); + gfarm_error_t (*group_add)(struct gfarm_group_info *); + gfarm_error_t (*group_modify)(struct db_group_modify_arg *); + gfarm_error_t (*group_remove)(char *); gfarm_error_t (*group_load)(void *, void (*)(void *, struct gfarm_group_info *)); - void (*inode_add)(struct gfs_stat *); - void (*inode_modify)(struct gfs_stat *); - void (*inode_nlink_modify)(struct db_inode_uint64_modify_arg *); - void (*inode_size_modify)(struct db_inode_uint64_modify_arg *); - void (*inode_mode_modify)(struct db_inode_uint32_modify_arg *); - void (*inode_user_modify)(struct db_inode_string_modify_arg *); - void (*inode_group_modify)(struct db_inode_string_modify_arg *); - void (*inode_atime_modify)(struct db_inode_timespec_modify_arg *); - void (*inode_mtime_modify)(struct db_inode_timespec_modify_arg *); - void (*inode_ctime_modify)(struct db_inode_timespec_modify_arg *); + gfarm_error_t (*inode_add)(struct gfs_stat *); + gfarm_error_t (*inode_modify)(struct gfs_stat *); + gfarm_error_t (*inode_nlink_modify)(struct db_inode_uint64_modify_arg *); + gfarm_error_t (*inode_size_modify)(struct db_inode_uint64_modify_arg *); + gfarm_error_t (*inode_mode_modify)(struct db_inode_uint32_modify_arg *); + gfarm_error_t (*inode_user_modify)(struct db_inode_string_modify_arg *); + gfarm_error_t (*inode_group_modify)(struct db_inode_string_modify_arg *); + gfarm_error_t (*inode_atime_modify)(struct db_inode_timespec_modify_arg *); + gfarm_error_t (*inode_mtime_modify)(struct db_inode_timespec_modify_arg *); + gfarm_error_t (*inode_ctime_modify)(struct db_inode_timespec_modify_arg *); /* inode_remove: never remove any inode to keep inode->i_gen */ gfarm_error_t (*inode_load)(void *, void (*)(void *, struct gfs_stat *)); - void (*inode_cksum_add)(struct db_inode_cksum_arg *); - void (*inode_cksum_modify)(struct db_inode_cksum_arg *); - void (*inode_cksum_remove)(struct db_inode_inum_arg *); + gfarm_error_t (*inode_cksum_add)(struct db_inode_cksum_arg *); + gfarm_error_t (*inode_cksum_modify)(struct db_inode_cksum_arg *); + gfarm_error_t (*inode_cksum_remove)(struct db_inode_inum_arg *); gfarm_error_t (*inode_cksum_load)(void *, void (*)(void *, gfarm_ino_t, char *, size_t, char *)); - void (*filecopy_add)(struct db_filecopy_arg *); - void (*filecopy_remove)(struct db_filecopy_arg *); + gfarm_error_t (*filecopy_add)(struct db_filecopy_arg *); + gfarm_error_t (*filecopy_remove)(struct db_filecopy_arg *); gfarm_error_t (*filecopy_load)(void *, void (*)(void *, gfarm_ino_t, char *)); - void (*deadfilecopy_add)(struct db_deadfilecopy_arg *); - void (*deadfilecopy_remove)(struct db_deadfilecopy_arg *); + gfarm_error_t (*deadfilecopy_add)(struct db_deadfilecopy_arg *); + gfarm_error_t (*deadfilecopy_remove)(struct db_deadfilecopy_arg *); gfarm_error_t (*deadfilecopy_load)(void *, void (*)(void *, gfarm_ino_t, gfarm_uint64_t, char *)); - void (*direntry_add)(struct db_direntry_arg *); - void (*direntry_remove)(struct db_direntry_arg *); + gfarm_error_t (*direntry_add)(struct db_direntry_arg *); + gfarm_error_t (*direntry_remove)(struct db_direntry_arg *); gfarm_error_t (*direntry_load)(void *, void (*)(void *, gfarm_ino_t, char *, int, gfarm_ino_t)); - void (*symlink_add)(struct db_symlink_arg *); - void (*symlink_remove)(struct db_inode_inum_arg *); + gfarm_error_t (*symlink_add)(struct db_symlink_arg *); + gfarm_error_t (*symlink_remove)(struct db_inode_inum_arg *); gfarm_error_t (*symlink_load)(void *, void (*)(void *, gfarm_ino_t, char *)); gfarm_error_t (*xattr_add)(struct db_xattr_arg *); gfarm_error_t (*xattr_modify)(struct db_xattr_arg *); gfarm_error_t (*xattr_remove)(struct db_xattr_arg *); + gfarm_error_t (*xattr_removeall)(struct db_xattr_arg *); gfarm_error_t (*xattr_get)(struct db_xattr_arg *); - gfarm_error_t (*xattr_list)(struct db_xattr_arg *); gfarm_error_t (*xattr_load)(void *, - void (*)(void *, struct xattr_info *)); + void (*)(void *, struct xattr_info *)); gfarm_error_t (*xmlattr_find)(struct db_xmlattr_find_arg *); }; Modified: gfarm_v2/trunk/server/gfmd/db_pgsql.c =================================================================== --- gfarm_v2/trunk/server/gfmd/db_pgsql.c 2009-03-26 14:22:07 UTC (rev 4135) +++ gfarm_v2/trunk/server/gfmd/db_pgsql.c 2009-03-27 04:24:57 UTC (rev 4136) @@ -858,7 +858,7 @@ return (GFARM_ERR_NO_ERROR); } -static void +static gfarm_error_t pgsql_host_update(struct gfarm_host_info *info, const char *sql, gfarm_error_t (*check)(PGresult *, const char *, const char *), int remove_all_aliases_first, @@ -872,7 +872,7 @@ char flags[GFARM_INT32STRLEN + 1]; if (!gfarm_pgsql_begin_with_retry("pgsql_host_add")) - return; + return GFARM_ERR_UNKNOWN; paramValues[0] = info->hostname; sprintf(port, "%d", info->port); @@ -899,42 +899,48 @@ if (e == GFARM_ERR_NO_ERROR) e = hostaliases_set(info); - gfarm_pgsql_exec_and_log( + return gfarm_pgsql_exec_and_log( e == GFARM_ERR_NO_ERROR ? "COMMIT" : "ROLLBACK", diag); } -static void +static gfarm_error_t gfarm_pgsql_host_add(struct gfarm_host_info *info) { - pgsql_host_update(info, + gfarm_error_t e; + + e = pgsql_host_update(info, "INSERT INTO Host (hostname, port, architecture, ncpu, flags) " "VALUES ($1, $2, $3, $4, $5)", gfarm_pgsql_check_insert, 0, "pgsql_host_add"); free(info); + return e; } -static void +static gfarm_error_t gfarm_pgsql_host_modify(struct db_host_modify_arg *arg) { + gfarm_error_t e; /* XXX FIXME: should use modflags, add_aliases and del_aliases */ - pgsql_host_update(&arg->hi, + e = pgsql_host_update(&arg->hi, "UPDATE Host " "SET port = $2, architecture = $3, ncpu = $4, flags = $5 " "WHERE hostname = $1", gfarm_pgsql_check_update_or_delete, 1, "pgsql_host_modify"); free(arg); + return e; } -static void +static gfarm_error_t gfarm_pgsql_host_remove(char *hostname) { + gfarm_error_t e; const char *paramValues[1]; paramValues[0] = hostname; - gfarm_pgsql_update_or_delete_with_retry( + e = gfarm_pgsql_update_or_delete_with_retry( "DELETE FROM Host WHERE hostname = $1", 1, /* number of params */ NULL, /* param types */ @@ -945,6 +951,7 @@ "pgsql_host_remove"); free(hostname); + return e; } static gfarm_error_t @@ -996,7 +1003,7 @@ return (GFARM_ERR_NO_ERROR); } -static void +static gfarm_error_t pgsql_user_call(struct gfarm_user_info *info, const char *sql, gfarm_error_t (*op)(const char *, int, const Oid *, const char *const *, const int *, const int *, int, @@ -1009,7 +1016,7 @@ paramValues[1] = info->homedir; paramValues[2] = info->realname; paramValues[3] = info->gsi_dn; - (*op)( + return (*op)( sql, 4, /* number of params */ NULL, /* param types */ @@ -1020,22 +1027,25 @@ diag); } -static void +static gfarm_error_t gfarm_pgsql_user_add(struct gfarm_user_info *info) { - pgsql_user_call(info, + gfarm_error_t e; + e = pgsql_user_call(info, "INSERT INTO GfarmUser (username, homedir, realname, gsiDN) " "VALUES ($1, $2, $3, $4)", gfarm_pgsql_insert_with_retry, "pgsql_user_add"); free(info); + return e; } -static void +static gfarm_error_t gfarm_pgsql_user_modify(struct db_user_modify_arg *arg) { - pgsql_user_call(&arg->ui, + gfarm_error_t e; + e = pgsql_user_call(&arg->ui, "UPDATE GfarmUser " "SET homedir = $2, realname = $3, gsiDN = $4 " "WHERE username = $1", @@ -1043,15 +1053,17 @@ "pgsql_user_modify"); free(arg); + return e; } -static void +static gfarm_error_t gfarm_pgsql_user_remove(char *username) { + gfarm_error_t e; const char *paramValues[1]; paramValues[0] = username; - gfarm_pgsql_update_or_delete_with_retry( + e = gfarm_pgsql_update_or_delete_with_retry( "DELETE FROM GfarmUser WHERE username = $1", 1, /* number of params */ NULL, /* param types */ @@ -1062,6 +1074,7 @@ "pgsql_user_remove"); free(username); + return e; } static gfarm_error_t @@ -1158,7 +1171,7 @@ return (GFARM_ERR_NO_ERROR); } -static void +static gfarm_error_t gfarm_pgsql_group_add(struct gfarm_group_info *info) { const char *paramValues[1]; @@ -1180,15 +1193,16 @@ if (e == GFARM_ERR_NO_ERROR) e = grpassign_set(info); - gfarm_pgsql_exec_and_log( + e = gfarm_pgsql_exec_and_log( e == GFARM_ERR_NO_ERROR ? "COMMIT" : "ROLLBACK", "pgsql_group_add"); } free(info); + return e; } -static void +static gfarm_error_t gfarm_pgsql_group_modify(struct db_group_modify_arg *arg) { struct gfarm_group_info *info = &arg->gi; @@ -1201,20 +1215,22 @@ if (e == GFARM_ERR_NO_ERROR) e = grpassign_set(info); - gfarm_pgsql_exec_and_log( + e = gfarm_pgsql_exec_and_log( e == GFARM_ERR_NO_ERROR ? "COMMIT" : "ROLLBACK", "pgsql_group_modify"); } free(arg); + return e; } -static void +static gfarm_error_t gfarm_pgsql_group_remove(char *groupname) { + gfarm_error_t e; const char *paramValues[1]; paramValues[0] = groupname; - gfarm_pgsql_update_or_delete_with_retry( + e = gfarm_pgsql_update_or_delete_with_retry( "DELETE FROM GfarmGroup WHERE groupname = $1", 1, /* number of params */ NULL, /* param types */ @@ -1225,6 +1241,7 @@ "pgsql_group_remove"); free(groupname); + return e; } static gfarm_error_t @@ -1264,13 +1281,14 @@ /**********************************************************************/ -static void +static gfarm_error_t pgsql_inode_call(struct gfs_stat *info, const char *sql, gfarm_error_t (*op)(const char *, int, const Oid *, const char *const *, const int *, const int *, int, const char *), const char *diag) { + gfarm_error_t e; const char *paramValues[13]; char inumber[GFARM_INT64STRLEN + 1]; char igen[GFARM_INT64STRLEN + 1]; @@ -1309,7 +1327,7 @@ sprintf(ctimensec, "%d", info->st_ctimespec.tv_nsec); paramValues[12] = ctimensec; - (*op)( + e = (*op)( sql, 13, /* number of params */ NULL, /* param types */ @@ -1320,12 +1338,13 @@ diag); free(info); + return e; } -static void +static gfarm_error_t gfarm_pgsql_inode_add(struct gfs_stat *info) { - pgsql_inode_call(info, + return pgsql_inode_call(info, "INSERT INTO INode (inumber, igen, nlink, size, mode, " "username, groupname, " "atimesec, atimensec, " @@ -1337,10 +1356,10 @@ "pgsql_inode_add"); } -static void +static gfarm_error_t gfarm_pgsql_inode_modify(struct gfs_stat *info) { - pgsql_inode_call(info, + return pgsql_inode_call(info, "UPDATE INode SET igen = $2, nlink = $3, size = $4, " "mode = $5, username = $6, groupname = $7, " "atimesec = $8, atimensec = $9, " @@ -1351,10 +1370,11 @@ "pgsql_inode_modify"); } -static void +static gfarm_error_t pgsql_inode_uint64_call(struct db_inode_uint64_modify_arg *arg, const char *sql, const char *diag) { + gfarm_error_t e; const char *paramValues[2]; char inumber[GFARM_INT64STRLEN + 1]; char uint64[GFARM_INT64STRLEN + 1]; @@ -1364,7 +1384,7 @@ sprintf(uint64, "%" GFARM_PRId64, arg->uint64); paramValues[1] = uint64; - gfarm_pgsql_update_or_delete_with_retry( + e = gfarm_pgsql_update_or_delete_with_retry( sql, 2, /* number of params */ NULL, /* param types */ @@ -1375,12 +1395,14 @@ diag); free(arg); + return e; } -static void +static gfarm_error_t pgsql_inode_uint32_call(struct db_inode_uint32_modify_arg *arg, const char *sql, const char *diag) { + gfarm_error_t e; const char *paramValues[2]; char inumber[GFARM_INT64STRLEN + 1]; char uint32[GFARM_INT32STRLEN + 1]; @@ -1390,7 +1412,7 @@ sprintf(uint32, "%d", arg->uint32); paramValues[1] = uint32; - gfarm_pgsql_update_or_delete_with_retry( + e = gfarm_pgsql_update_or_delete_with_retry( sql, 2, /* number of params */ NULL, /* param types */ @@ -1401,12 +1423,14 @@ diag); free(arg); + return e; } -static void +static gfarm_error_t pgsql_inode_string_call(struct db_inode_string_modify_arg *arg, const char *sql, const char *diag) { + gfarm_error_t e; const char *paramValues[2]; char inumber[GFARM_INT64STRLEN + 1]; @@ -1414,7 +1438,7 @@ paramValues[0] = inumber; paramValues[1] = arg->string; - gfarm_pgsql_update_or_delete_with_retry( + e = gfarm_pgsql_update_or_delete_with_retry( sql, 2, /* number of params */ NULL, /* param types */ @@ -1425,12 +1449,14 @@ diag); free(arg); + return e; } -static void +static gfarm_error_t pgsql_inode_timespec_call(struct db_inode_timespec_modify_arg *arg, const char *sql, const char *diag) { + gfarm_error_t e; const char *paramValues[3]; char inumber[GFARM_INT64STRLEN + 1]; char sec[GFARM_INT64STRLEN + 1]; @@ -1443,7 +1469,7 @@ sprintf(nsec, "%d", arg->time.tv_nsec); paramValues[2] = nsec; - gfarm_pgsql_update_or_delete_with_retry( + e = gfarm_pgsql_update_or_delete_with_retry( sql, 3, /* number of params */ NULL, /* param types */ @@ -1454,68 +1480,69 @@ diag); free(arg); + return e; } -static void +static gfarm_error_t gfarm_pgsql_inode_nlink_modify(struct db_inode_uint64_modify_arg *arg) { - pgsql_inode_uint64_call(arg, + return pgsql_inode_uint64_call(arg, "UPDATE INode SET nlink = $2 WHERE inumber = $1", "pgsql_inode_nlink_modify"); } -static void +static gfarm_error_t gfarm_pgsql_inode_size_modify(struct db_inode_uint64_modify_arg *arg) { - pgsql_inode_uint64_call(arg, + return pgsql_inode_uint64_call(arg, "UPDATE INode SET size = $2 WHERE inumber = $1", "pgsql_inode_size_modify"); } -static void +static gfarm_error_t gfarm_pgsql_inode_mode_modify(struct db_inode_uint32_modify_arg *arg) { - pgsql_inode_uint32_call(arg, + return pgsql_inode_uint32_call(arg, "UPDATE INode SET mode = $2 WHERE inumber = $1", "pgsql_inode_mode_modify"); } -static void +static gfarm_error_t gfarm_pgsql_inode_user_modify(struct db_inode_string_modify_arg *arg) { - pgsql_inode_string_call(arg, + return pgsql_inode_string_call(arg, "UPDATE INode SET username = $2 WHERE inumber = $1", "pgsql_inode_user_modify"); } -static void +static gfarm_error_t gfarm_pgsql_inode_group_modify(struct db_inode_string_modify_arg *arg) { - pgsql_inode_string_call(arg, + return pgsql_inode_string_call(arg, "UPDATE INode SET groupname = $2 WHERE inumber = $1", "pgsql_inode_group_modify"); } -static void +static gfarm_error_t gfarm_pgsql_inode_atime_modify(struct db_inode_timespec_modify_arg *arg) { - pgsql_inode_timespec_call(arg, + return pgsql_inode_timespec_call(arg, "UPDATE INode SET atimesec = $2, atimensec = $3 WHERE inumber = $1", "pgsql_inode_atime_modify"); } -static void +static gfarm_error_t gfarm_pgsql_inode_mtime_modify(struct db_inode_timespec_modify_arg *arg) { - pgsql_inode_timespec_call(arg, + return pgsql_inode_timespec_call(arg, "UPDATE INode SET mtimesec = $2, mtimensec = $3 WHERE inumber = $1", "pgsql_inode_mtime_modify"); } -static void +static gfarm_error_t gfarm_pgsql_inode_ctime_modify(struct db_inode_timespec_modify_arg *arg) { - pgsql_inode_timespec_call(arg, + return pgsql_inode_timespec_call(arg, "UPDATE INode SET ctimesec = $2, ctimensec = $3 WHERE inumber = $1", "pgsql_inode_ctime_modify"); } @@ -1572,13 +1599,14 @@ /**********************************************************************/ -static void +static gfarm_error_t pgsql_inode_cksum_call(struct db_inode_cksum_arg *arg, const char *sql, gfarm_error_t (*op)(const char *, int, const Oid *, const char *const *, const int *, const int *, int, const char *), const char *diag) { + gfarm_error_t e; const char *paramValues[3]; char inumber[GFARM_INT64STRLEN + 1]; @@ -1586,7 +1614,7 @@ paramValues[0] = inumber; paramValues[1] = arg->type; paramValues[2] = arg->sum; - (*op)( + e = (*op)( sql, 3, /* number of params */ NULL, /* param types */ @@ -1597,21 +1625,23 @@ diag); free(arg); + return e; } -static void +static gfarm_error_t pgsql_inode_inum_call(struct db_inode_inum_arg *arg, const char *sql, gfarm_error_t (*op)(const char *, int, const Oid *, const char *const *, const int *, const int *, int, const char *), const char *diag) { + gfarm_error_t e; const char *paramValues[1]; char inumber[GFARM_INT64STRLEN + 1]; sprintf(inumber, "%" GFARM_PRId64, arg->inum); paramValues[0] = inumber; - (*op)( + e = (*op)( sql, 1, /* number of params */ NULL, /* param types */ @@ -1622,30 +1652,31 @@ diag); free(arg); + return e; } -static void +static gfarm_error_t gfarm_pgsql_file_info_add(struct db_inode_cksum_arg *arg) { - pgsql_inode_cksum_call(arg, + return pgsql_inode_cksum_call(arg, "INSERT INTO FileInfo (inumber, checksumType, checksum) " "VALUES ($1, $2, $3)", gfarm_pgsql_insert_with_retry, "pgsql_cksum_add"); } -static void +static gfarm_error_t gfarm_pgsql_file_info_modify(struct db_inode_cksum_arg *arg) { - pgsql_inode_cksum_call(arg, + return pgsql_inode_cksum_call(arg, "UPDATE FileInfo SET checksumType = $2, checksum = $3 " "WHERE inumber = $1", gfarm_pgsql_update_or_delete_with_retry, "pgsql_cksum_modify"); } -static void +static gfarm_error_t gfarm_pgsql_file_info_remove(struct db_inode_inum_arg *arg) { - pgsql_inode_inum_call(arg, + return pgsql_inode_inum_call(arg, "DELETE FROM FileInfo WHERE inumber = $1", gfarm_pgsql_update_or_delete_with_retry, "pgsql_cksum_remove"); @@ -1691,20 +1722,21 @@ /**********************************************************************/ -static void +static gfarm_error_t pgsql_filecopy_call(struct db_filecopy_arg *arg, const char *sql, gfarm_error_t (*op)(const char *, int, const Oid *, const char *const *, const int *, const int *, int, const char *), const char *diag) { + gfarm_error_t e; const char *paramValues[2]; char inumber[GFARM_INT64STRLEN + 1]; sprintf(inumber, "%" GFARM_PRId64, arg->inum); paramValues[0] = inumber; paramValues[1] = arg->hostname; - (*op)( + e = (*op)( sql, 2, /* number of params */ NULL, /* param types */ @@ -1715,21 +1747,22 @@ diag); free(arg); + return e; } -static void +static gfarm_error_t gfarm_pgsql_filecopy_add(struct db_filecopy_arg *arg) { - pgsql_filecopy_call(arg, + return pgsql_filecopy_call(arg, "INSERT INTO FileCopy (inumber, hostname) VALUES ($1, $2)", gfarm_pgsql_insert_with_retry, "pgsql_filecopy_add"); } -static void +static gfarm_error_t gfarm_pgsql_filecopy_remove(struct db_filecopy_arg *arg) { - pgsql_filecopy_call(arg, + return pgsql_filecopy_call(arg, "DELETE FROM FileCopy WHERE inumber = $1 AND hostname = $2", gfarm_pgsql_update_or_delete_with_retry, "pgsql_filecopy_remove"); @@ -1773,13 +1806,14 @@ /**********************************************************************/ -static void +static gfarm_error_t pgsql_deadfilecopy_call(struct db_deadfilecopy_arg *arg, const char *sql, gfarm_error_t (*op)(const char *, int, const Oid *, const char *const *, const int *, const int *, int, const char *), const char *diag) { + gfarm_error_t e; const char *paramValues[3]; char inumber[GFARM_INT64STRLEN + 1]; char igen[GFARM_INT64STRLEN + 1]; @@ -1789,7 +1823,7 @@ sprintf(igen, "%" GFARM_PRId64, arg->igen); paramValues[1] = igen; paramValues[2] = arg->hostname; - (*op)( + e = (*op)( sql, 3, /* number of params */ NULL, /* param types */ @@ -1800,22 +1834,23 @@ diag); free(arg); + return e; } -static void +static gfarm_error_t gfarm_pgsql_deadfilecopy_add(struct db_deadfilecopy_arg *arg) { - pgsql_deadfilecopy_call(arg, + return pgsql_deadfilecopy_call(arg, "INSERT INTO DeadFileCopy (inumber, igen, hostname) " "VALUES ($1, $2, $3)", gfarm_pgsql_insert_with_retry, "pgsql_deadfilecopy_add"); } -static void +static gfarm_error_t gfarm_pgsql_deadfilecopy_remove(struct db_deadfilecopy_arg *arg) { - pgsql_deadfilecopy_call(arg, + return pgsql_deadfilecopy_call(arg, "DELETE FROM DeadFileCopy " "WHERE inumber = $1 AND igen = $2 AND hostname = $3", gfarm_pgsql_update_or_delete_with_retry, @@ -1863,9 +1898,10 @@ /**********************************************************************/ -static void +static gfarm_error_t gfarm_pgsql_direntry_add(struct db_direntry_arg *arg) { + gfarm_error_t e; const char *paramValues[3]; char dir_inumber[GFARM_INT64STRLEN + 1]; char entry_inumber[GFARM_INT64STRLEN + 1]; @@ -1875,7 +1911,7 @@ paramValues[1] = arg->entry_name; sprintf(entry_inumber, "%" GFARM_PRId64, arg->entry_inum); paramValues[2] = entry_inumber; - gfarm_pgsql_insert_with_retry( + e = gfarm_pgsql_insert_with_retry( "INSERT INTO DirEntry (dirINumber, entryName, entryINumber) " "VALUES ($1, $2, $3)", 3, /* number of params */ @@ -1887,18 +1923,20 @@ "direntry_add"); free(arg); + return e; } -static void +static gfarm_error_t gfarm_pgsql_direntry_remove(struct db_direntry_arg *arg) { + gfarm_error_t e; const char *paramValues[2]; char dir_inumber[GFARM_INT64STRLEN + 1]; sprintf(dir_inumber, "%" GFARM_PRId64, arg->dir_inum); paramValues[0] = dir_inumber; paramValues[1] = arg->entry_name; - gfarm_pgsql_update_or_delete_with_retry( + e = gfarm_pgsql_update_or_delete_with_retry( "DELETE FROM DirEntry " "WHERE dirINumber = $1 AND entryName = $2", 2, /* number of params */ @@ -1910,6 +1948,7 @@ "direntry_remove"); free(arg); + return e; } static void @@ -1952,20 +1991,21 @@ /**********************************************************************/ -static void +static gfarm_error_t pgsql_symlink_call(struct db_symlink_arg *arg, const char *sql, gfarm_error_t (*op)(const char *, int, const Oid *, const char *const *, const int *, const int *, int, const char *), const char *diag) { + gfarm_error_t e; const char *paramValues[2]; char inumber[GFARM_INT64STRLEN + 1]; sprintf(inumber, "%" GFARM_PRId64, arg->inum); paramValues[0] = inumber; paramValues[1] = arg->source_path; - (*op)( + e = (*op)( sql, 2, /* number of params */ NULL, /* param types */ @@ -1976,21 +2016,22 @@ diag); free(arg); + return e; } -static void +static gfarm_error_t gfarm_pgsql_symlink_add(struct db_symlink_arg *arg) { - pgsql_symlink_call(arg, + return pgsql_symlink_call(arg, "INSERT INTO Symlink (inumber, sourcePath) VALUES ($1, $2)", gfarm_pgsql_insert_with_retry, "pgsql_symlink_add"); } -static void +static gfarm_error_t gfarm_pgsql_symlink_remove(struct db_inode_inum_arg *arg) { - pgsql_inode_inum_call(arg, + return pgsql_inode_inum_call(arg, "DELETE FROM Symlink WHERE inumber = $1", gfarm_pgsql_update_or_delete_with_retry, "pgsql_symlink_remove"); @@ -2163,6 +2204,40 @@ } static gfarm_error_t +gfarm_pgsql_xattr_removeall(struct db_xattr_arg *arg) +{ + gfarm_error_t e; + const char *paramValues[1]; + char inumber[GFARM_INT64STRLEN + 1]; + char *diag; + char *command; + + sprintf(inumber, "%" GFARM_PRId64, arg->inum); + paramValues[0] = inumber; + if (arg->xmlMode) { + command = "DELETE FROM XmlAttr " + "WHERE inumber = $1"; + diag = "pgsql_xmlattr_removeall"; + } else { + command = "DELETE FROM XAttr " + "WHERE inumber = $1"; + diag = "pgsql_xattr_removeall"; + } + e = gfarm_pgsql_update_or_delete_with_retry( + command, + 1, + NULL, /* param types */ + paramValues, + NULL, /* param lengths */ + NULL, /* param formats */ + 0, /* ask for text results */ + diag); + + free(arg); + return e; +} + +static gfarm_error_t pgsql_xattr_set_attrvalue_string(PGresult *res, int row, void *vinfo) { struct xattr_info *info = vinfo; @@ -2237,82 +2312,6 @@ } static gfarm_error_t -pgsql_xattr_set_attrname(PGresult *res, int row, void *vinfo) -{ - struct xattr_info *info = vinfo; - - info->attrname = pgsql_get_string(res, row, "attrname"); - info->namelen = strlen(info->attrname) + 1; // include '\0' - return (GFARM_ERR_NO_ERROR); -} - -static gfarm_error_t -gfarm_pgsql_xattr_list(struct db_xattr_arg *arg) -{ - gfarm_error_t e; - const char *paramValues[1]; - char inumber[GFARM_INT64STRLEN + 1]; - char *diag; - char *command; - int i, n = 0, len; - struct xattr_info *vinfo = NULL; - char *buffer, *p; - - *arg->sizep = 0; - *arg->valuep = NULL; - - sprintf(inumber, "%" GFARM_PRId64, arg->inum); - paramValues[0] = inumber; - - if (arg->xmlMode) { - command = "SELECT attrname FROM XmlAttr WHERE inumber = $1"; - diag = "pgsql_xmlattr_list"; - } else { - command = "SELECT attrname FROM XAttr WHERE inumber = $1"; - diag = "pgsql_xattr_list"; - } - - e = gfarm_pgsql_generic_get_all( - command, - 1, paramValues, - &n, &vinfo, - &gfarm_base_xattr_info_ops, pgsql_xattr_set_attrname, - diag); - if (e == GFARM_ERR_NO_SUCH_OBJECT) { - e = GFARM_ERR_NO_ERROR; - goto quit; - } - if (e != GFARM_ERR_NO_ERROR) - goto quit; - - len = 0; - for (i = 0; i < n; i++) { - // NOTE: namelen including '\0' - len += vinfo[i].namelen; - } - GFARM_MALLOC_ARRAY(buffer, len); - if (buffer == NULL) { - gfarm_base_generic_info_free_all(n, vinfo, - &gfarm_base_xattr_info_ops); - e = GFARM_ERR_NO_MEMORY; - goto quit; - } - - p = buffer; - for (i = 0; i < n; i++) { - memcpy(p, vinfo[i].attrname, vinfo[i].namelen); - p += vinfo[i].namelen; - } - *arg->sizep = len; - *arg->valuep = buffer; - gfarm_base_generic_info_free_all(n, vinfo, - &gfarm_base_xattr_info_ops); -quit: - free(arg); - return e; -} - -static gfarm_error_t pgsql_xattr_set_inum_and_attrname(PGresult *res, int row, void *vinfo) { struct xattr_info *info = vinfo; @@ -2324,10 +2323,11 @@ } static gfarm_error_t -gfarm_pgsql_xattr_load0(int xmlMode, +gfarm_pgsql_xattr_load(void *closure, void (*callback)(void *, struct xattr_info *)) { gfarm_error_t e; + int xmlMode = (closure != NULL) ? *(int*)closure : 0; char *command, *diag; struct xattr_info *vinfo; int i, n; @@ -2360,16 +2360,13 @@ } static gfarm_error_t -gfarm_pgsql_xattr_load(void *closure, - void (*callback)(void *, struct xattr_info *)) +pgsql_xattr_set_attrname(PGresult *res, int row, void *vinfo) { - gfarm_error_t e; + struct xattr_info *info = vinfo; - // ignore closure to distinguish xmlMode - if ((e = gfarm_pgsql_xattr_load0(0, callback)) - == GFARM_ERR_NO_ERROR) - e = gfarm_pgsql_xattr_load0(1, callback); - return e; + info->attrname = pgsql_get_string(res, row, "attrname"); + info->namelen = strlen(info->attrname) + 1; // include '\0' + return (GFARM_ERR_NO_ERROR); } static gfarm_error_t @@ -2392,7 +2389,7 @@ * Array size > 0 if some attrvalue matched XPath expr, 0 if not. */ command = "SELECT attrname FROM XmlAttr " - "WHERE inumber = $1 AND array_upper(xpath($2, attrvalue), 1) > 0" + "WHERE inumber = $1 AND array_upper(xpath($2, attrvalue),1) > 0" "ORDER BY attrname"; diag = "pgsql_xmlattr_find"; @@ -2473,8 +2470,8 @@ gfarm_pgsql_xattr_add, gfarm_pgsql_xattr_modify, gfarm_pgsql_xattr_remove, + gfarm_pgsql_xattr_removeall, gfarm_pgsql_xattr_get, - gfarm_pgsql_xattr_list, gfarm_pgsql_xattr_load, gfarm_pgsql_xmlattr_find, }; Modified: gfarm_v2/trunk/server/gfmd/inode.c =================================================================== --- gfarm_v2/trunk/server/gfmd/inode.c 2009-03-26 14:22:07 UTC (rev 4135) +++ gfarm_v2/trunk/server/gfmd/inode.c 2009-03-27 04:24:57 UTC (rev 4136) @@ -340,6 +340,13 @@ &inode->i_xmlattrs : &inode->i_xattrs; struct xattr_entry *entry = NULL; + if (xattrs->head == NULL) + return; + + e = db_xattr_removeall(xmlMode, inode->i_number); + if (e != GFARM_ERR_OPERATION_NOT_SUPPORTED) + return; + entry = xattrs->head; while (entry != NULL) { e = db_xattr_remove(xmlMode, inode->i_number, entry->name); @@ -2181,14 +2188,13 @@ xattr_add_one(void *closure, struct xattr_info *info) { struct inode *inode = inode_lookup(info->inum); - int xmlMode; struct xattrs *xattrs; if (inode == NULL) gflog_error("xattr_add_one: no file %" GFARM_PRId64, info->inum); else { - xmlMode = (closure != NULL) ? *(int*)c... [truncated message content] |