static int undup_read(const char *path, char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { char b[PATH_MAX+1]; int n, ret; struct stub *stub; double t0, t1; t0 = rtc(); n = snprintf(b, PATH_MAX, "%s/%s", state->basedir, path); if (n > PATH_MAX) return -ENAMETOOLONG; stub = (struct stub *)fi->fh; if (!stub) return -EIO; debug("undup_read off=%lld size=%d path=%s len=%lld\n", (long long)offset, (int)size, path, (long long)stub->hdr.len); ret = stub_read(state, stub, buf, size, offset); debug("undup_read return %d errno=%d\n", ret, errno); t1 = rtc(); count_event(COUNT_READ, t1 - t0, size); state_wrlock(state); count_maybe_dump(state, t1); state_unlock(state); return ret; }
void state_fini(state *s) { if (s->lock > 0) state_unlock(s); num_clear(s->counter); num_clear(s->latest_card); num_clear(s->current_card); num_clear(s->salt_mask); num_clear(s->code_mask); num_clear(s->max_card); num_clear(s->max_code); if (s->prompt) { const int length = strlen(s->prompt); memset(s->prompt, 0, length); free(s->prompt); s->prompt = NULL; } free(s->username); /* Clear the rest of memory, this includes sequence_key */ memset(s, 0, sizeof(*s)); }
int nlm4_Unlock(nfs_arg_t * parg /* IN */ , exportlist_t * pexport /* IN */ , fsal_op_context_t * pcontext /* IN */ , cache_inode_client_t * pclient /* INOUT */ , hash_table_t * ht /* INOUT */ , struct svc_req *preq /* IN */ , nfs_res_t * pres /* OUT */ ) { nlm4_unlockargs * arg = &parg->arg_nlm4_unlock; cache_entry_t * pentry; state_status_t state_status = CACHE_INODE_SUCCESS; char buffer[MAXNETOBJ_SZ * 2]; state_nsm_client_t * nsm_client; state_nlm_client_t * nlm_client; state_owner_t * nlm_owner; state_lock_desc_t lock; int rc; netobj_to_string(&arg->cookie, buffer, sizeof(buffer)); LogDebug(COMPONENT_NLM, "REQUEST PROCESSING: Calling nlm4_Unlock svid=%d off=%llx len=%llx cookie=%s", (int) arg->alock.svid, (unsigned long long) arg->alock.l_offset, (unsigned long long) arg->alock.l_len, buffer); if(!copy_netobj(&pres->res_nlm4test.cookie, &arg->cookie)) { pres->res_nlm4.stat.stat = NLM4_FAILED; LogDebug(COMPONENT_NLM, "REQUEST RESULT: nlm4_Unlock %s", lock_result_str(pres->res_nlm4.stat.stat)); return NFS_REQ_OK; } if(in_nlm_grace_period()) { pres->res_nlm4.stat.stat = NLM4_DENIED_GRACE_PERIOD; LogDebug(COMPONENT_NLM, "REQUEST RESULT: nlm4_Unlock %s", lock_result_str(pres->res_nlm4.stat.stat)); return NFS_REQ_OK; } rc = nlm_process_parameters(preq, FALSE, /* exlcusive doesn't matter */ &arg->alock, &lock, ht, &pentry, pcontext, pclient, CARE_NOT, /* unlock doesn't care if owner is found */ &nsm_client, &nlm_client, &nlm_owner, NULL); if(rc >= 0) { /* Present the error back to the client */ pres->res_nlm4.stat.stat = (nlm4_stats)rc; LogDebug(COMPONENT_NLM, "REQUEST RESULT: nlm4_Unlock %s", lock_result_str(pres->res_nlm4.stat.stat)); return NFS_REQ_OK; } if(state_unlock(pentry, pcontext, nlm_owner, NULL, &lock, pclient, &state_status) != STATE_SUCCESS) { /* Unlock could fail in the FSAL and make a bit of a mess, especially if * we are in out of memory situation. Such an error is logged by * Cache Inode. */ pres->res_nlm4test.test_stat.stat = nlm_convert_state_error(state_status); } else { pres->res_nlm4.stat.stat = NLM4_GRANTED; } /* Release the NLM Client and NLM Owner references we have */ dec_nsm_client_ref(nsm_client); dec_nlm_client_ref(nlm_client); dec_state_owner_ref(nlm_owner, pclient); LogDebug(COMPONENT_NLM, "REQUEST RESULT: nlm4_Unlock %s", lock_result_str(pres->res_nlm4.stat.stat)); return NFS_REQ_OK; }
int state_store(state *s, int remove) { cfg_t *cfg = cfg_get(); int locked = 0; int ret = 1; assert(!(s->new_key && remove)); if (s->new_key == 1) { /* State musn't be locked already! */ assert(s->lock <= 0); if (s->lock > 0) return STATE_LOCK_ERROR; /* Lock state for this write exclusively */ ret = state_lock(s); if (ret != 0) { print(PRINT_ERROR, "Unable to lock file for writing!\n"); return STATE_LOCK_ERROR; } locked = 1; } if (s->lock <= 0) { print(PRINT_ERROR, "Trying to save state data into DB " "without previously locked DB.\n"); return 2; } s->new_key = 0; switch (cfg->db) { case CONFIG_DB_USER: case CONFIG_DB_GLOBAL: ret = db_file_store(s, remove); break; /* case CONFIG_DB_MYSQL: ret = db_mysql_store(s, remove); break; case CONFIG_DB_LDAP: ret = db_ldap_store(s, remove); break; */ default: assert(0); ret = 1; break; } if (locked) { /* Unlock recently locked state */ if (state_unlock(s) != 0) { print(PRINT_WARN, "Strange error while unlocking the file"); } } return ret; }
int nfs4_op_locku(struct nfs_argop4 *op, compound_data_t * data, struct nfs_resop4 *resp) { #ifndef _WITH_NFSV4_LOCKS resp->resop = NFS4_OP_LOCKU; res_LOCKU4.status = NFS4ERR_LOCK_NOTSUPP; return res_LOCKU4.status; #else char __attribute__ ((__unused__)) funcname[] = "nfs4_op_locku"; state_status_t state_status; state_t * pstate_found = NULL; state_owner_t * plock_owner; state_lock_desc_t lock_desc; unsigned int rc = 0; const char * tag = "LOCKU"; LogDebug(COMPONENT_NFS_V4_LOCK, "Entering NFS v4 LOCKU handler -----------------------------------------------------"); /* Initialize to sane default */ resp->resop = NFS4_OP_LOCKU; /* If there is no FH */ if(nfs4_Is_Fh_Empty(&(data->currentFH))) { res_LOCKU4.status = NFS4ERR_NOFILEHANDLE; return res_LOCKU4.status; } /* If the filehandle is invalid */ if(nfs4_Is_Fh_Invalid(&(data->currentFH))) { res_LOCKU4.status = NFS4ERR_BADHANDLE; return res_LOCKU4.status; } /* Tests if the Filehandle is expired (for volatile filehandle) */ if(nfs4_Is_Fh_Expired(&(data->currentFH))) { res_LOCKU4.status = NFS4ERR_FHEXPIRED; return res_LOCKU4.status; } /* LOCKU is done only on a file */ if(data->current_filetype != REGULAR_FILE) { /* Type of the entry is not correct */ switch (data->current_filetype) { case DIRECTORY: res_LOCKU4.status = NFS4ERR_ISDIR; return res_LOCKU4.status; default: res_LOCKU4.status = NFS4ERR_INVAL; return res_LOCKU4.status; } } /* Convert lock parameters to internal types */ switch(arg_LOCKU4.locktype) { case READ_LT: case READW_LT: lock_desc.sld_type = STATE_LOCK_R; break; case WRITE_LT: case WRITEW_LT: lock_desc.sld_type = STATE_LOCK_W; break; } lock_desc.sld_offset = arg_LOCKU4.offset; if(arg_LOCKU4.length != STATE_LOCK_OFFSET_EOF) lock_desc.sld_length = arg_LOCKU4.length; else lock_desc.sld_length = 0; /* Check stateid correctness and get pointer to state */ if((rc = nfs4_Check_Stateid(&arg_LOCKU4.lock_stateid, data->current_entry, 0LL, &pstate_found, data, STATEID_SPECIAL_FOR_LOCK, tag)) != NFS4_OK) { res_LOCKU4.status = rc; return res_LOCKU4.status; } plock_owner = pstate_found->state_powner; /* Check seqid (lock_seqid or open_seqid) */ if(!Check_nfs4_seqid(plock_owner, arg_LOCKU4.seqid, op, data, resp, tag)) { /* Response is all setup for us and LogDebug told what was wrong */ return res_LOCKU4.status; } /* Lock length should not be 0 */ if(arg_LOCKU4.length == 0LL) { res_LOCKU4.status = NFS4ERR_INVAL; /* Save the response in the lock owner */ Copy_nfs4_state_req(plock_owner, arg_LOCKU4.seqid, op, data, resp, tag); return res_LOCKU4.status; } /* Check for range overflow * Remember that a length with all bits set to 1 means "lock until the end of file" (RFC3530, page 157) */ if(lock_desc.sld_length > (STATE_LOCK_OFFSET_EOF - lock_desc.sld_offset)) { res_LOCKU4.status = NFS4ERR_INVAL; /* Save the response in the lock owner */ Copy_nfs4_state_req(plock_owner, arg_LOCKU4.seqid, op, data, resp, tag); return res_LOCKU4.status; } LogLock(COMPONENT_NFS_V4_LOCK, NIV_FULL_DEBUG, tag, data->current_entry, data->pcontext, plock_owner, &lock_desc); /* Now we have a lock owner and a stateid. * Go ahead and push unlock into SAL (and FSAL). */ if(state_unlock(data->current_entry, data->pcontext, plock_owner, pstate_found, &lock_desc, data->pclient, &state_status) != STATE_SUCCESS) { res_LOCKU4.status = nfs4_Errno_state(state_status); /* Save the response in the lock owner */ Copy_nfs4_state_req(plock_owner, arg_LOCKU4.seqid, op, data, resp, tag); return res_LOCKU4.status; } /* Successful exit */ res_LOCKU4.status = NFS4_OK; /* Handle stateid/seqid for success */ update_stateid(pstate_found, &res_LOCKU4.LOCKU4res_u.lock_stateid, data, tag); /* Save the response in the lock owner */ Copy_nfs4_state_req(plock_owner, arg_LOCKU4.seqid, op, data, resp, tag); return res_LOCKU4.status; #endif } /* nfs4_op_locku */
int nlm4_Unlock(nfs_arg_t *args, struct svc_req *req, nfs_res_t *res) { nlm4_unlockargs *arg = &args->arg_nlm4_unlock; struct fsal_obj_handle *obj; state_status_t state_status = STATE_SUCCESS; char buffer[MAXNETOBJ_SZ * 2] = "\0"; state_nsm_client_t *nsm_client; state_nlm_client_t *nlm_client; state_owner_t *nlm_owner; fsal_lock_param_t lock; int rc; state_t *state; /* NLM doesn't have a BADHANDLE error, nor can rpc_execute deal with * responding to an NLM_*_MSG call, so we check here if the export is * NULL and if so, handle the response. */ if (op_ctx->ctx_export == NULL) { res->res_nlm4.stat.stat = NLM4_STALE_FH; LogInfo(COMPONENT_NLM, "INVALID HANDLE: nlm4_Unlock"); return NFS_REQ_OK; } netobj_to_string(&arg->cookie, buffer, sizeof(buffer)); LogDebug(COMPONENT_NLM, "REQUEST PROCESSING: Calling nlm4_Unlock svid=%d off=%llx len=%llx cookie=%s", (int)arg->alock.svid, (unsigned long long)arg->alock.l_offset, (unsigned long long)arg->alock.l_len, buffer); copy_netobj(&res->res_nlm4test.cookie, &arg->cookie); if (nfs_in_grace()) { res->res_nlm4.stat.stat = NLM4_DENIED_GRACE_PERIOD; LogDebug(COMPONENT_NLM, "REQUEST RESULT: nlm4_Unlock %s", lock_result_str(res->res_nlm4.stat.stat)); return NFS_REQ_OK; } /* unlock doesn't care if owner is found */ rc = nlm_process_parameters(req, false, &arg->alock, &lock, &obj, CARE_NOT, &nsm_client, &nlm_client, &nlm_owner, NULL, 0, &state); if (rc >= 0) { /* resent the error back to the client */ res->res_nlm4.stat.stat = (nlm4_stats) rc; LogDebug(COMPONENT_NLM, "REQUEST RESULT: nlm4_Unlock %s", lock_result_str(res->res_nlm4.stat.stat)); return NFS_REQ_OK; } if (state != NULL) state_status = state_unlock(obj, state, nlm_owner, false, 0, &lock); if (state_status != STATE_SUCCESS) { /* Unlock could fail in the FSAL and make a bit of a mess, * especially if we are in out of memory situation. Such an * error is logged by Cache Inode. */ res->res_nlm4test.test_stat.stat = nlm_convert_state_error(state_status); } else { res->res_nlm4.stat.stat = NLM4_GRANTED; } /* Release the NLM Client and NLM Owner references we have */ if (state != NULL) dec_state_t_ref(state); dec_nsm_client_ref(nsm_client); dec_nlm_client_ref(nlm_client); dec_state_owner_ref(nlm_owner); obj->obj_ops.put_ref(obj); LogDebug(COMPONENT_NLM, "REQUEST RESULT: nlm4_Unlock %s", lock_result_str(res->res_nlm4.stat.stat)); return NFS_REQ_OK; }