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