| 1 | /* |
|---|
| 2 | * (C) 2003 Clemson University and The University of Chicago |
|---|
| 3 | * |
|---|
| 4 | * See COPYING in top-level directory. |
|---|
| 5 | */ |
|---|
| 6 | |
|---|
| 7 | /** \file |
|---|
| 8 | * \ingroup mgmtint |
|---|
| 9 | * |
|---|
| 10 | * PVFS2 management interface routines for removing specific directory |
|---|
| 11 | * entries. These are used primarily for file system repair purposes, |
|---|
| 12 | * although they can also be used to create specific inconsistency cases |
|---|
| 13 | * for testing of failure tolerance. |
|---|
| 14 | */ |
|---|
| 15 | |
|---|
| 16 | #include <string.h> |
|---|
| 17 | #include <assert.h> |
|---|
| 18 | |
|---|
| 19 | #include "client-state-machine.h" |
|---|
| 20 | #include "pint-util.h" |
|---|
| 21 | #include "pvfs2-debug.h" |
|---|
| 22 | #include "job.h" |
|---|
| 23 | #include "gossip.h" |
|---|
| 24 | #include "str-utils.h" |
|---|
| 25 | #include "pint-cached-config.h" |
|---|
| 26 | #include "PINT-reqproto-encode.h" |
|---|
| 27 | #include "pvfs2-internal.h" |
|---|
| 28 | |
|---|
| 29 | extern job_context_id pint_client_sm_context; |
|---|
| 30 | |
|---|
| 31 | static int mgmt_remove_dirent_comp_fn( |
|---|
| 32 | void *v_p, struct PVFS_server_resp *resp_p, int i); |
|---|
| 33 | |
|---|
| 34 | %% |
|---|
| 35 | |
|---|
| 36 | machine pvfs2_client_mgmt_remove_dirent_sm |
|---|
| 37 | { |
|---|
| 38 | state init |
|---|
| 39 | { |
|---|
| 40 | run mgmt_remove_dirent_init; |
|---|
| 41 | default => parent_getattr; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | state parent_getattr |
|---|
| 45 | { |
|---|
| 46 | jump pvfs2_client_getattr_sm; |
|---|
| 47 | success => remove_dirent_setup_msgpair; |
|---|
| 48 | default => cleanup; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | state remove_dirent_setup_msgpair |
|---|
| 52 | { |
|---|
| 53 | run mgmt_remove_dirent_setup_msgpair; |
|---|
| 54 | success => remove_dirent_xfer_msgpair; |
|---|
| 55 | default => cleanup; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | state remove_dirent_xfer_msgpair |
|---|
| 59 | { |
|---|
| 60 | jump pvfs2_msgpairarray_sm; |
|---|
| 61 | default => cleanup; |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | state cleanup |
|---|
| 65 | { |
|---|
| 66 | run mgmt_remove_dirent_cleanup; |
|---|
| 67 | default => terminate; |
|---|
| 68 | } |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | %% |
|---|
| 72 | |
|---|
| 73 | /** Initiate removal of a specific directory entry. |
|---|
| 74 | */ |
|---|
| 75 | PVFS_error PVFS_imgmt_remove_dirent( |
|---|
| 76 | PVFS_object_ref parent_ref, |
|---|
| 77 | char *entry, |
|---|
| 78 | PVFS_credentials *credentials, |
|---|
| 79 | PVFS_mgmt_op_id *op_id, |
|---|
| 80 | PVFS_hint hints, |
|---|
| 81 | void *user_ptr) |
|---|
| 82 | { |
|---|
| 83 | PVFS_error ret = -PVFS_EINVAL; |
|---|
| 84 | PINT_smcb *smcb = NULL; |
|---|
| 85 | PINT_client_sm *sm_p = NULL; |
|---|
| 86 | |
|---|
| 87 | gossip_debug(GOSSIP_CLIENT_DEBUG, |
|---|
| 88 | "PVFS_imgmt_remove_dirent entered\n"); |
|---|
| 89 | |
|---|
| 90 | if ((parent_ref.handle == PVFS_HANDLE_NULL) || |
|---|
| 91 | (parent_ref.fs_id == PVFS_FS_ID_NULL)) |
|---|
| 92 | { |
|---|
| 93 | gossip_err("invalid (NULL) required argument\n"); |
|---|
| 94 | return ret; |
|---|
| 95 | } |
|---|
| 96 | |
|---|
| 97 | PINT_smcb_alloc(&smcb, PVFS_MGMT_REMOVE_DIRENT, |
|---|
| 98 | sizeof(struct PINT_client_sm), |
|---|
| 99 | client_op_state_get_machine, |
|---|
| 100 | client_state_machine_terminate, |
|---|
| 101 | pint_client_sm_context); |
|---|
| 102 | if (smcb == NULL) |
|---|
| 103 | { |
|---|
| 104 | return -PVFS_ENOMEM; |
|---|
| 105 | } |
|---|
| 106 | sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT); |
|---|
| 107 | |
|---|
| 108 | PINT_init_msgarray_params(sm_p, parent_ref.fs_id); |
|---|
| 109 | PINT_init_sysint_credentials(sm_p->cred_p, credentials); |
|---|
| 110 | sm_p->parent_ref = parent_ref; |
|---|
| 111 | sm_p->u.mgmt_remove_dirent.entry = entry; |
|---|
| 112 | PVFS_hint_copy(hints, &sm_p->hints); |
|---|
| 113 | |
|---|
| 114 | gossip_debug( |
|---|
| 115 | GOSSIP_CLIENT_DEBUG, "Trying to remove dirent %s under %llu,%d\n", |
|---|
| 116 | sm_p->u.mgmt_remove_dirent.entry, llu(parent_ref.handle), |
|---|
| 117 | parent_ref.fs_id); |
|---|
| 118 | |
|---|
| 119 | return PINT_client_state_machine_post( |
|---|
| 120 | smcb, op_id, user_ptr); |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | /** Remove a specific directory entry. |
|---|
| 124 | */ |
|---|
| 125 | PVFS_error PVFS_mgmt_remove_dirent( |
|---|
| 126 | PVFS_object_ref parent_ref, |
|---|
| 127 | char *entry, |
|---|
| 128 | PVFS_credentials *credentials, |
|---|
| 129 | PVFS_hint hints) |
|---|
| 130 | { |
|---|
| 131 | PVFS_error ret = -PVFS_EINVAL, error = 0; |
|---|
| 132 | PVFS_mgmt_op_id op_id; |
|---|
| 133 | |
|---|
| 134 | gossip_debug(GOSSIP_CLIENT_DEBUG, |
|---|
| 135 | "PVFS_mgmt_remove_dirent entered\n"); |
|---|
| 136 | |
|---|
| 137 | ret = PVFS_imgmt_remove_dirent( |
|---|
| 138 | parent_ref, entry, credentials, &op_id, hints, NULL); |
|---|
| 139 | if (ret) |
|---|
| 140 | { |
|---|
| 141 | PVFS_perror_gossip("PVFS_imgmt_remove_dirent call", ret); |
|---|
| 142 | error = ret; |
|---|
| 143 | } |
|---|
| 144 | else |
|---|
| 145 | { |
|---|
| 146 | ret = PVFS_mgmt_wait(op_id, "remove_dirent", &error); |
|---|
| 147 | if (ret) |
|---|
| 148 | { |
|---|
| 149 | PVFS_perror_gossip("PVFS_mgmt_wait call", ret); |
|---|
| 150 | error = ret; |
|---|
| 151 | } |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | PINT_mgmt_release(op_id); |
|---|
| 155 | return error; |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | /****************************************************************/ |
|---|
| 159 | |
|---|
| 160 | static PINT_sm_action mgmt_remove_dirent_init( |
|---|
| 161 | struct PINT_smcb *smcb, job_status_s *js_p) |
|---|
| 162 | { |
|---|
| 163 | struct PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT); |
|---|
| 164 | |
|---|
| 165 | gossip_debug(GOSSIP_CLIENT_DEBUG, "mgmt_remove_dirent_init called\n"); |
|---|
| 166 | |
|---|
| 167 | assert(js_p->error_code == 0); |
|---|
| 168 | |
|---|
| 169 | PINT_SM_GETATTR_STATE_FILL( |
|---|
| 170 | sm_p->getattr, |
|---|
| 171 | sm_p->parent_ref, |
|---|
| 172 | PVFS_ATTR_COMMON_ALL|PVFS_ATTR_DIR_DIRENT_FILES, |
|---|
| 173 | PVFS_TYPE_DIRECTORY, |
|---|
| 174 | 0); |
|---|
| 175 | |
|---|
| 176 | return SM_ACTION_COMPLETE; |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | static PINT_sm_action mgmt_remove_dirent_setup_msgpair( |
|---|
| 180 | struct PINT_smcb *smcb, job_status_s *js_p) |
|---|
| 181 | { |
|---|
| 182 | struct PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT); |
|---|
| 183 | int ret = -PVFS_EINVAL; |
|---|
| 184 | PINT_sm_msgpair_state *msg_p = NULL; |
|---|
| 185 | |
|---|
| 186 | js_p->error_code = 0; |
|---|
| 187 | |
|---|
| 188 | PINT_msgpair_init(&sm_p->msgarray_op); |
|---|
| 189 | msg_p = &sm_p->msgarray_op.msgpair; |
|---|
| 190 | |
|---|
| 191 | /* TODO: Need to find the correct dirent_handle */ |
|---|
| 192 | /* TODO: Need to call PINT_free_object_attr? */ |
|---|
| 193 | PINT_SERVREQ_MGMT_REMOVE_DIRENT_FILL( |
|---|
| 194 | msg_p->req, |
|---|
| 195 | *sm_p->cred_p, |
|---|
| 196 | sm_p->parent_ref.fs_id, |
|---|
| 197 | sm_p->parent_ref.handle, |
|---|
| 198 | sm_p->getattr.attr.u.dir.dirdata_handles[0], |
|---|
| 199 | sm_p->u.mgmt_remove_dirent.entry, |
|---|
| 200 | sm_p->hints); |
|---|
| 201 | |
|---|
| 202 | gossip_debug(GOSSIP_REMOVE_DEBUG, "- doing MGMT_REMOVE_DIRENT %s " |
|---|
| 203 | "under %llu,%d\n", sm_p->u.mgmt_remove_dirent.entry, |
|---|
| 204 | llu(sm_p->parent_ref.handle), sm_p->parent_ref.fs_id); |
|---|
| 205 | |
|---|
| 206 | msg_p->fs_id = sm_p->parent_ref.fs_id; |
|---|
| 207 | msg_p->handle = sm_p->parent_ref.handle; |
|---|
| 208 | msg_p->retry_flag = PVFS_MSGPAIR_NO_RETRY; |
|---|
| 209 | msg_p->comp_fn = mgmt_remove_dirent_comp_fn; |
|---|
| 210 | |
|---|
| 211 | ret = PINT_cached_config_map_to_server( |
|---|
| 212 | &msg_p->svr_addr, msg_p->handle, msg_p->fs_id); |
|---|
| 213 | |
|---|
| 214 | if (ret) |
|---|
| 215 | { |
|---|
| 216 | gossip_err("Failed to map server address\n"); |
|---|
| 217 | js_p->error_code = ret; |
|---|
| 218 | } |
|---|
| 219 | |
|---|
| 220 | PINT_sm_push_frame(smcb, 0, &sm_p->msgarray_op); |
|---|
| 221 | return SM_ACTION_COMPLETE; |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | static int mgmt_remove_dirent_comp_fn( |
|---|
| 225 | void *v_p, struct PVFS_server_resp *resp_p, int index) |
|---|
| 226 | { |
|---|
| 227 | PINT_smcb *smcb = v_p; |
|---|
| 228 | PINT_client_sm *sm_p __attribute__((unused)) = |
|---|
| 229 | PINT_sm_frame(smcb, PINT_MSGPAIR_PARENT_SM); |
|---|
| 230 | |
|---|
| 231 | assert(resp_p->op == PVFS_SERV_MGMT_REMOVE_DIRENT); |
|---|
| 232 | |
|---|
| 233 | if (resp_p->status == 0) |
|---|
| 234 | { |
|---|
| 235 | gossip_debug( |
|---|
| 236 | GOSSIP_CLIENT_DEBUG, |
|---|
| 237 | " mgmt_remove_dirent_comp_fn: dirent %s under %llu,%d " |
|---|
| 238 | "removed\n", sm_p->u.mgmt_remove_dirent.entry, |
|---|
| 239 | llu(sm_p->parent_ref.handle), sm_p->parent_ref.fs_id); |
|---|
| 240 | } |
|---|
| 241 | return resp_p->status; |
|---|
| 242 | } |
|---|
| 243 | |
|---|
| 244 | static PINT_sm_action mgmt_remove_dirent_cleanup( |
|---|
| 245 | struct PINT_smcb *smcb, job_status_s *js_p) |
|---|
| 246 | { |
|---|
| 247 | struct PINT_client_sm *sm_p = PINT_sm_frame(smcb, PINT_FRAME_CURRENT); |
|---|
| 248 | gossip_debug(GOSSIP_CLIENT_DEBUG, |
|---|
| 249 | "mgmt_remove_dirent_cleanup called\n"); |
|---|
| 250 | |
|---|
| 251 | PINT_SM_GETATTR_STATE_CLEAR(sm_p->getattr); |
|---|
| 252 | sm_p->error_code = js_p->error_code; |
|---|
| 253 | |
|---|
| 254 | PINT_SET_OP_COMPLETE; |
|---|
| 255 | return SM_ACTION_TERMINATE; |
|---|
| 256 | } |
|---|
| 257 | |
|---|
| 258 | /* |
|---|
| 259 | * Local variables: |
|---|
| 260 | * mode: c |
|---|
| 261 | * c-indent-level: 4 |
|---|
| 262 | * c-basic-offset: 4 |
|---|
| 263 | * End: |
|---|
| 264 | * |
|---|
| 265 | * vim: ft=c ts=8 sts=4 sw=4 expandtab |
|---|
| 266 | */ |
|---|