| 1 | /* |
|---|
| 2 | * (C) 2001 Clemson University and The University of Chicago |
|---|
| 3 | * |
|---|
| 4 | * See COPYING in top-level directory. |
|---|
| 5 | */ |
|---|
| 6 | |
|---|
| 7 | #include <string.h> |
|---|
| 8 | #include <assert.h> |
|---|
| 9 | |
|---|
| 10 | #include "client-state-machine.h" |
|---|
| 11 | #include "state-machine-fns.h" |
|---|
| 12 | #include "pvfs2-debug.h" |
|---|
| 13 | #include "job.h" |
|---|
| 14 | #include "gossip.h" |
|---|
| 15 | #include "str-utils.h" |
|---|
| 16 | |
|---|
| 17 | #include "pinode-helper.h" |
|---|
| 18 | #include "pint-dcache.h" |
|---|
| 19 | #include "pint-servreq.h" |
|---|
| 20 | #include "pint-bucket.h" |
|---|
| 21 | #include "pcache.h" |
|---|
| 22 | #include "PINT-reqproto-encode.h" |
|---|
| 23 | #include "shared-state-methods.h" |
|---|
| 24 | |
|---|
| 25 | int sm_common_parent_getattr_setup_msgpair(PINT_client_sm *sm_p, |
|---|
| 26 | job_status_s *js_p) |
|---|
| 27 | { |
|---|
| 28 | int ret = -1; |
|---|
| 29 | |
|---|
| 30 | gossip_debug(CLIENT_DEBUG, |
|---|
| 31 | "sm_common_parent_getattr_setup_msgpair\n"); |
|---|
| 32 | |
|---|
| 33 | memset(&sm_p->msgpair, 0, sizeof(PINT_client_sm_msgpair_state)); |
|---|
| 34 | |
|---|
| 35 | /* parameter range checks */ |
|---|
| 36 | assert(sm_p->parent_ref.fs_id != 0); |
|---|
| 37 | assert(sm_p->parent_ref.handle != 0); |
|---|
| 38 | |
|---|
| 39 | /* fill in getattr request */ |
|---|
| 40 | PINT_SERVREQ_GETATTR_FILL(sm_p->msgpair.req, |
|---|
| 41 | *sm_p->cred_p, |
|---|
| 42 | sm_p->parent_ref.fs_id, |
|---|
| 43 | sm_p->parent_ref.handle, |
|---|
| 44 | PVFS_ATTR_COMMON_ALL); |
|---|
| 45 | |
|---|
| 46 | /* fill in msgpair structure components */ |
|---|
| 47 | sm_p->msgpair.fs_id = sm_p->parent_ref.fs_id; |
|---|
| 48 | sm_p->msgpair.handle = sm_p->parent_ref.handle; |
|---|
| 49 | sm_p->msgpair.comp_fn = sm_common_getattr_comp_fn; |
|---|
| 50 | |
|---|
| 51 | ret = PINT_bucket_map_to_server(&sm_p->msgpair.svr_addr, |
|---|
| 52 | sm_p->msgpair.handle, |
|---|
| 53 | sm_p->msgpair.fs_id); |
|---|
| 54 | if (ret != 0) |
|---|
| 55 | { |
|---|
| 56 | gossip_err("Error: failure mapping to server.\n"); |
|---|
| 57 | assert(ret < 0); /* return value range check */ |
|---|
| 58 | assert(0); /* TODO: real error handling */ |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | js_p->error_code = 0; |
|---|
| 62 | return 1; |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | int sm_common_parent_getattr_failure(PINT_client_sm *sm_p, |
|---|
| 66 | job_status_s *js_p) |
|---|
| 67 | { |
|---|
| 68 | gossip_debug(CLIENT_DEBUG, "sm_common_parent_getattr_failure\n"); |
|---|
| 69 | |
|---|
| 70 | return 1; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | int sm_common_dspace_create_setup_msgpair(PINT_client_sm *sm_p, |
|---|
| 74 | job_status_s *js_p) |
|---|
| 75 | { |
|---|
| 76 | gossip_debug(CLIENT_DEBUG, |
|---|
| 77 | "state: sm_common_dspace_create_setup_msgpair\n"); |
|---|
| 78 | |
|---|
| 79 | return 1; |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | int sm_common_dspace_create_failure(PINT_client_sm *sm_p, |
|---|
| 83 | job_status_s *js_p) |
|---|
| 84 | { |
|---|
| 85 | return 1; |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | int sm_common_crdirent_setup_msgpair(PINT_client_sm *sm_p, |
|---|
| 89 | job_status_s *js_p) |
|---|
| 90 | { |
|---|
| 91 | gossip_debug(CLIENT_DEBUG, "state: sm_common_crdirent_setup_msgpair\n"); |
|---|
| 92 | return 1; |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | int sm_common_crdirent_failure(PINT_client_sm *sm_p, |
|---|
| 96 | job_status_s *js_p); |
|---|
| 97 | int sm_common_setattr_setup_msgpair(PINT_client_sm *sm_p, |
|---|
| 98 | job_status_s *js_p); |
|---|
| 99 | int sm_common_setattr_failure(PINT_client_sm *sm_p, |
|---|
| 100 | job_status_s *js_p); |
|---|
| 101 | |
|---|
| 102 | /* |
|---|
| 103 | shared/common msgpair completion functions |
|---|
| 104 | */ |
|---|
| 105 | int sm_common_getattr_comp_fn(void *v_p, |
|---|
| 106 | struct PVFS_server_resp *resp_p, |
|---|
| 107 | int index) |
|---|
| 108 | { |
|---|
| 109 | int ret = 0; |
|---|
| 110 | PVFS_object_attr *attr = NULL; |
|---|
| 111 | PINT_client_sm *sm_p = (PINT_client_sm *) v_p; |
|---|
| 112 | |
|---|
| 113 | assert(resp_p->op == PVFS_SERV_GETATTR); |
|---|
| 114 | |
|---|
| 115 | gossip_debug(CLIENT_DEBUG, "sm_common_getattr_comp_fn\n"); |
|---|
| 116 | |
|---|
| 117 | /* if we get an error, just return immediately, don't try to |
|---|
| 118 | * actually fill anything in. |
|---|
| 119 | */ |
|---|
| 120 | if (resp_p->status != 0) |
|---|
| 121 | { |
|---|
| 122 | gossip_err("Error: getattr failure\n"); |
|---|
| 123 | return resp_p->status; |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | /* |
|---|
| 127 | if we didn't get a cache hit, we're making a |
|---|
| 128 | copy of the attributes here so that we can add |
|---|
| 129 | a pcache entry later in cleanup. |
|---|
| 130 | */ |
|---|
| 131 | if (!sm_p->pcache_hit) |
|---|
| 132 | { |
|---|
| 133 | PINT_pcache_object_attr_deep_copy( |
|---|
| 134 | &sm_p->pcache_attr, &resp_p->u.getattr.attr); |
|---|
| 135 | } |
|---|
| 136 | |
|---|
| 137 | /* |
|---|
| 138 | if we got a cache hit, use those attributes, |
|---|
| 139 | otherwise use the real server replied attrs |
|---|
| 140 | */ |
|---|
| 141 | attr = (sm_p->pcache_hit ? |
|---|
| 142 | &sm_p->pinode->attr : |
|---|
| 143 | &resp_p->u.getattr.attr); |
|---|
| 144 | assert(attr); |
|---|
| 145 | |
|---|
| 146 | if (attr->objtype == PVFS_TYPE_DIRECTORY) |
|---|
| 147 | { |
|---|
| 148 | /* |
|---|
| 149 | check permissions against parent directory to determine |
|---|
| 150 | if we're allowed to create a new entry there |
|---|
| 151 | */ |
|---|
| 152 | ret = check_perms(*attr, attr->perms, |
|---|
| 153 | sm_p->cred_p->uid, sm_p->cred_p->gid); |
|---|
| 154 | if (ret < 0) |
|---|
| 155 | { |
|---|
| 156 | gossip_err("Error: Permission failure\n"); |
|---|
| 157 | return -PVFS_EPERM; |
|---|
| 158 | } |
|---|
| 159 | } |
|---|
| 160 | else |
|---|
| 161 | { |
|---|
| 162 | gossip_err("Error: Parent is not a directory\n"); |
|---|
| 163 | return -PVFS_ENOTDIR; |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | /* |
|---|
| 167 | if our parent directory attributes are good, and not present |
|---|
| 168 | int the pcache, put them in the pcache now |
|---|
| 169 | */ |
|---|
| 170 | if (!sm_p->pcache_hit) |
|---|
| 171 | { |
|---|
| 172 | PINT_pinode *pinode = |
|---|
| 173 | PINT_pcache_lookup(sm_p->u.getattr.object_ref); |
|---|
| 174 | if (!pinode) |
|---|
| 175 | { |
|---|
| 176 | pinode = PINT_pcache_pinode_alloc(); |
|---|
| 177 | assert(pinode); |
|---|
| 178 | } |
|---|
| 179 | pinode->refn = sm_p->u.getattr.object_ref; |
|---|
| 180 | pinode->size = ((attr->mask & PVFS_ATTR_DATA_ALL) ? |
|---|
| 181 | attr->u.data.size : 0); |
|---|
| 182 | |
|---|
| 183 | PINT_pcache_object_attr_deep_copy( |
|---|
| 184 | &pinode->attr, &resp_p->u.getattr.attr); |
|---|
| 185 | |
|---|
| 186 | PINT_pcache_set_valid(pinode); |
|---|
| 187 | PINT_pcache_release(pinode); |
|---|
| 188 | } |
|---|
| 189 | return 0; |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | int sm_common_create_comp_fn(void *v_p, |
|---|
| 193 | struct PVFS_server_resp *resp_p, |
|---|
| 194 | int index); |
|---|
| 195 | int sm_common_crdirent_comp_fn(void *v_p, |
|---|
| 196 | struct PVFS_server_resp *resp_p, |
|---|
| 197 | int index); |
|---|
| 198 | int sm_common_setattr_comp_fn(void *v_p, |
|---|
| 199 | struct PVFS_server_resp *resp_p, |
|---|
| 200 | int index); |
|---|
| 201 | |
|---|
| 202 | |
|---|
| 203 | /* |
|---|
| 204 | * Local variables: |
|---|
| 205 | * c-indent-level: 4 |
|---|
| 206 | * c-basic-offset: 4 |
|---|
| 207 | * End: |
|---|
| 208 | * |
|---|
| 209 | * vim: ts=8 sts=4 sw=4 noexpandtab |
|---|
| 210 | */ |
|---|