コード例 #1
0
ファイル: locks.c プロジェクト: 7799/linux
/**
 * Encode the flock and fcntl locks for the given inode into the ceph_filelock
 * array. Must be called with inode->i_lock already held.
 * If we encounter more of a specific lock type than expected, return -ENOSPC.
 */
int ceph_encode_locks_to_buffer(struct inode *inode,
				struct ceph_filelock *flocks,
				int num_fcntl_locks, int num_flock_locks)
{
	struct file_lock *lock;
	int err = 0;
	int seen_fcntl = 0;
	int seen_flock = 0;
	int l = 0;

	dout("encoding %d flock and %d fcntl locks", num_flock_locks,
	     num_fcntl_locks);

	for (lock = inode->i_flock; lock != NULL; lock = lock->fl_next) {
		if (lock->fl_flags & FL_POSIX) {
			++seen_fcntl;
			if (seen_fcntl > num_fcntl_locks) {
				err = -ENOSPC;
				goto fail;
			}
			err = lock_to_ceph_filelock(lock, &flocks[l]);
			if (err)
				goto fail;
			++l;
		}
	}
	for (lock = inode->i_flock; lock != NULL; lock = lock->fl_next) {
		if (lock->fl_flags & FL_FLOCK) {
			++seen_flock;
			if (seen_flock > num_flock_locks) {
				err = -ENOSPC;
				goto fail;
			}
			err = lock_to_ceph_filelock(lock, &flocks[l]);
			if (err)
				goto fail;
			++l;
		}
	}
fail:
	return err;
}
コード例 #2
0
ファイル: dir.c プロジェクト: AK101111/linux
static struct dentry *
__dcache_find_get_entry(struct dentry *parent, u64 idx,
			struct ceph_readdir_cache_control *cache_ctl)
{
	struct inode *dir = d_inode(parent);
	struct dentry *dentry;
	unsigned idx_mask = (PAGE_SIZE / sizeof(struct dentry *)) - 1;
	loff_t ptr_pos = idx * sizeof(struct dentry *);
	pgoff_t ptr_pgoff = ptr_pos >> PAGE_SHIFT;

	if (ptr_pos >= i_size_read(dir))
		return NULL;

	if (!cache_ctl->page || ptr_pgoff != page_index(cache_ctl->page)) {
		ceph_readdir_cache_release(cache_ctl);
		cache_ctl->page = find_lock_page(&dir->i_data, ptr_pgoff);
		if (!cache_ctl->page) {
			dout(" page %lu not found\n", ptr_pgoff);
			return ERR_PTR(-EAGAIN);
		}
		/* reading/filling the cache are serialized by
		   i_mutex, no need to use page lock */
		unlock_page(cache_ctl->page);
		cache_ctl->dentries = kmap(cache_ctl->page);
	}

	cache_ctl->index = idx & idx_mask;

	rcu_read_lock();
	spin_lock(&parent->d_lock);
	/* check i_size again here, because empty directory can be
	 * marked as complete while not holding the i_mutex. */
	if (ceph_dir_is_complete_ordered(dir) && ptr_pos < i_size_read(dir))
		dentry = cache_ctl->dentries[cache_ctl->index];
	else
		dentry = NULL;
	spin_unlock(&parent->d_lock);
	if (dentry && !lockref_get_not_dead(&dentry->d_lockref))
		dentry = NULL;
	rcu_read_unlock();
	return dentry ? : ERR_PTR(-EAGAIN);
}
コード例 #3
0
ファイル: file.c プロジェクト: AshishNamdev/linux
static void ceph_aio_complete(struct inode *inode,
			      struct ceph_aio_request *aio_req)
{
	struct ceph_inode_info *ci = ceph_inode(inode);
	int ret;

	if (!atomic_dec_and_test(&aio_req->pending_reqs))
		return;

	ret = aio_req->error;
	if (!ret)
		ret = aio_req->total_len;

	dout("ceph_aio_complete %p rc %d\n", inode, ret);

	if (ret >= 0 && aio_req->write) {
		int dirty;

		loff_t endoff = aio_req->iocb->ki_pos + aio_req->total_len;
		if (endoff > i_size_read(inode)) {
			if (ceph_inode_set_size(inode, endoff))
				ceph_check_caps(ci, CHECK_CAPS_AUTHONLY, NULL);
		}

		spin_lock(&ci->i_ceph_lock);
		ci->i_inline_version = CEPH_INLINE_NONE;
		dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_FILE_WR,
					       &aio_req->prealloc_cf);
		spin_unlock(&ci->i_ceph_lock);
		if (dirty)
			__mark_inode_dirty(inode, dirty);

	}

	ceph_put_cap_refs(ci, (aio_req->write ? CEPH_CAP_FILE_WR :
						CEPH_CAP_FILE_RD));

	aio_req->iocb->ki_complete(aio_req->iocb, ret, 0);

	ceph_free_cap_flush(aio_req->prealloc_cf);
	kfree(aio_req);
}
コード例 #4
0
ファイル: super.c プロジェクト: Abioy/kasan
static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf)
{
	struct ceph_fs_client *fsc = ceph_inode_to_client(dentry->d_inode);
	struct ceph_monmap *monmap = fsc->client->monc.monmap;
	struct ceph_statfs st;
	u64 fsid;
	int err;

	dout("statfs\n");
	err = ceph_monc_do_statfs(&fsc->client->monc, &st);
	if (err < 0)
		return err;

	/* fill in kstatfs */
	buf->f_type = CEPH_SUPER_MAGIC;  /* ?? */

	/*
	 * express utilization in terms of large blocks to avoid
	 * overflow on 32-bit machines.
	 *
	 * NOTE: for the time being, we make bsize == frsize to humor
	 * not-yet-ancient versions of glibc that are broken.
	 * Someday, we will probably want to report a real block
	 * size...  whatever that may mean for a network file system!
	 */
	buf->f_bsize = 1 << CEPH_BLOCK_SHIFT;
	buf->f_frsize = 1 << CEPH_BLOCK_SHIFT;
	buf->f_blocks = le64_to_cpu(st.kb) >> (CEPH_BLOCK_SHIFT-10);
	buf->f_bfree = le64_to_cpu(st.kb_avail) >> (CEPH_BLOCK_SHIFT-10);
	buf->f_bavail = le64_to_cpu(st.kb_avail) >> (CEPH_BLOCK_SHIFT-10);

	buf->f_files = le64_to_cpu(st.num_objects);
	buf->f_ffree = -1;
	buf->f_namelen = NAME_MAX;

	/* leave fsid little-endian, regardless of host endianness */
	fsid = *(u64 *)(&monmap->fsid) ^ *((u64 *)&monmap->fsid + 1);
	buf->f_fsid.val[0] = fsid & 0xffffffff;
	buf->f_fsid.val[1] = fsid >> 32;

	return 0;
}
コード例 #5
0
ファイル: SingleSource.cpp プロジェクト: minsulander/moon
	void SingleSource::realize()
	{
		if (sample.valid() && AudioManager::instance().isActive()) {
			Source::realize();
			if (sourceID == AL_NONE)
				return;
			try {
				alSourcei(sourceID, AL_BUFFER, sample->getBufferID());
				CHECK_AL_ERROR_SOURCE(set sample);
				if (shouldAutoPlay())
					play();
				failed = false;
			} catch (AudioException& e) {
				if (!failed)
					dout(ERROR, AUDIO) << "Source " << getName() << ": " << e.what() << "\n";
				Source::unrealize();
				failed = true;
			}
		}
	}
コード例 #6
0
ファイル: buffer.c プロジェクト: mikuhatsune001/linux2.6.32
struct ceph_buffer *ceph_buffer_new(size_t len, gfp_t gfp)
{
	struct ceph_buffer *b;

	b = kmalloc(sizeof(*b), gfp);
	if (!b)
		return NULL;

	b->vec.iov_base = ceph_kvmalloc(len, gfp);
	if (!b->vec.iov_base) {
		kfree(b);
		return NULL;
	}

	kref_init(&b->kref);
	b->alloc_len = len;
	b->vec.iov_len = len;
	dout("buffer_new %p\n", b);
	return b;
}
コード例 #7
0
static int crush_decode_list_bucket(void **p, void *end,
				    struct crush_bucket_list *b)
{
	int j;
	dout("crush_decode_list_bucket %p to %p\n", *p, end);
	b->item_weights = kcalloc(b->h.size, sizeof(u32), GFP_NOFS);
	if (b->item_weights == NULL)
		return -ENOMEM;
	b->sum_weights = kcalloc(b->h.size, sizeof(u32), GFP_NOFS);
	if (b->sum_weights == NULL)
		return -ENOMEM;
	ceph_decode_need(p, end, 2 * b->h.size * sizeof(u32), bad);
	for (j = 0; j < b->h.size; j++) {
		b->item_weights[j] = ceph_decode_32(p);
		b->sum_weights[j] = ceph_decode_32(p);
	}
	return 0;
bad:
	return -EINVAL;
}
コード例 #8
0
ファイル: inode.c プロジェクト: nos1609/Chrono_Kernel-1
/*
 * find/create a frag in the tree
 */
static struct ceph_inode_frag *__get_or_create_frag(struct ceph_inode_info *ci,
						    u32 f)
{
	struct rb_node **p;
	struct rb_node *parent = NULL;
	struct ceph_inode_frag *frag;
	int c;

	p = &ci->i_fragtree.rb_node;
	while (*p) {
		parent = *p;
		frag = rb_entry(parent, struct ceph_inode_frag, node);
		c = ceph_frag_compare(f, frag->frag);
		if (c < 0)
			p = &(*p)->rb_left;
		else if (c > 0)
			p = &(*p)->rb_right;
		else
			return frag;
	}

	frag = kmalloc(sizeof(*frag), GFP_NOFS);
	if (!frag) {
		pr_err("__get_or_create_frag ENOMEM on %p %llx.%llx "
		       "frag %x\n", &ci->vfs_inode,
		       ceph_vinop(&ci->vfs_inode), f);
		return ERR_PTR(-ENOMEM);
	}
	frag->frag = f;
	frag->split_by = 0;
	frag->mds = -1;
	frag->ndist = 0;

	rb_link_node(&frag->node, parent, p);
	rb_insert_color(&frag->node, &ci->i_fragtree);

	dout("get_or_create_frag added %llx.%llx frag %x\n",
	     ceph_vinop(&ci->vfs_inode), f);
	return frag;
}
コード例 #9
0
ファイル: ioctl.c プロジェクト: 119-org/hi3518-osdrv
long ceph_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
	dout("ioctl file %p cmd %u arg %lu\n", file, cmd, arg);
	switch (cmd) {
	case CEPH_IOC_GET_LAYOUT:
		return ceph_ioctl_get_layout(file, (void __user *)arg);

	case CEPH_IOC_SET_LAYOUT:
		return ceph_ioctl_set_layout(file, (void __user *)arg);

	case CEPH_IOC_SET_LAYOUT_POLICY:
		return ceph_ioctl_set_layout_policy(file, (void __user *)arg);

	case CEPH_IOC_GET_DATALOC:
		return ceph_ioctl_get_dataloc(file, (void __user *)arg);

	case CEPH_IOC_LAZYIO:
		return ceph_ioctl_lazyio(file);
	}

	return -ENOTTY;
}
コード例 #10
0
ファイル: export.c プロジェクト: SimonPe/linux
/*
 * get parent, if possible.
 *
 * FIXME: we could do better by querying the mds to discover the
 * parent.
 */
static struct dentry *ceph_fh_to_parent(struct super_block *sb,
					 struct fid *fid,
					int fh_len, int fh_type)
{
	struct ceph_nfs_confh *cfh = (void *)fid->raw;
	struct ceph_vino vino;
	struct inode *inode;
	struct dentry *dentry;
	int err;

	if (fh_type == 1)
		return ERR_PTR(-ESTALE);
	if (fh_len < sizeof(*cfh) / 4)
		return ERR_PTR(-ESTALE);

	pr_debug("fh_to_parent %llx/%d\n", cfh->parent_ino,
		 cfh->parent_name_hash);

	vino.ino = cfh->ino;
	vino.snap = CEPH_NOSNAP;
	inode = ceph_find_inode(sb, vino);
	if (!inode)
		return ERR_PTR(-ESTALE);

	dentry = d_obtain_alias(inode);
	if (IS_ERR(dentry)) {
		pr_err("fh_to_parent %llx -- inode %p but ENOMEM\n",
		       cfh->ino, inode);
		iput(inode);
		return dentry;
	}
	err = ceph_init_dentry(dentry);
	if (err < 0) {
		iput(inode);
		return ERR_PTR(err);
	}
	dout("fh_to_parent %llx %p dentry %p\n", cfh->ino, inode, dentry);
	return dentry;
}
コード例 #11
0
static void ceph_monc_handle_map(struct ceph_mon_client *monc,
				 struct ceph_msg *msg)
{
	struct ceph_client *client = monc->client;
	struct ceph_monmap *monmap = NULL, *old = monc->monmap;
	void *p, *end;

	mutex_lock(&monc->mutex);

	dout("handle_monmap\n");
	p = msg->front.iov_base;
	end = p + msg->front.iov_len;

	monmap = ceph_monmap_decode(p, end);
	if (IS_ERR(monmap)) {
		pr_err("problem decoding monmap, %d\n",
		       (int)PTR_ERR(monmap));
		goto out;
	}

	if (ceph_check_fsid(monc->client, &monmap->fsid) < 0) {
		kfree(monmap);
		goto out;
	}

	client->monc.monmap = monmap;
	kfree(old);

	if (!client->have_fsid) {
		client->have_fsid = true;
		mutex_unlock(&monc->mutex);
		ceph_debugfs_client_init(client);
		goto out_unlocked;
	}
out:
	mutex_unlock(&monc->mutex);
out_unlocked:
	wake_up_all(&client->auth_wq);
}
コード例 #12
0
ファイル: super.c プロジェクト: flwh/Alcatel_OT_985_kernel
static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf)
{
	struct ceph_client *client = ceph_inode_to_client(dentry->d_inode);
	struct ceph_monmap *monmap = client->monc.monmap;
	struct ceph_statfs st;
	u64 fsid;
	int err;

	dout("statfs\n");
	err = ceph_monc_do_statfs(&client->monc, &st);
	if (err < 0)
		return err;

	/* fill in kstatfs */
	buf->f_type = CEPH_SUPER_MAGIC;  /* ?? */

	/*
	 * express utilization in terms of large blocks to avoid
	 * overflow on 32-bit machines.
	 */
	buf->f_bsize = 1 << CEPH_BLOCK_SHIFT;
	buf->f_blocks = le64_to_cpu(st.kb) >> (CEPH_BLOCK_SHIFT-10);
	buf->f_bfree = (le64_to_cpu(st.kb) - le64_to_cpu(st.kb_used)) >>
		(CEPH_BLOCK_SHIFT-10);
	buf->f_bavail = le64_to_cpu(st.kb_avail) >> (CEPH_BLOCK_SHIFT-10);

	buf->f_files = le64_to_cpu(st.num_objects);
	buf->f_ffree = -1;
	buf->f_namelen = NAME_MAX;
	buf->f_frsize = PAGE_CACHE_SIZE;

	/* leave fsid little-endian, regardless of host endianness */
	fsid = *(u64 *)(&monmap->fsid) ^ *((u64 *)&monmap->fsid + 1);
	buf->f_fsid.val[0] = fsid & 0xffffffff;
	buf->f_fsid.val[1] = fsid >> 32;

	return 0;
}
コード例 #13
0
ファイル: auth.c プロジェクト: A2109devs/lenovo_a2109a_kernel
int ceph_build_auth_request(struct ceph_auth_client *ac,
			   void *msg_buf, size_t msg_len)
{
	struct ceph_mon_request_header *monhdr = msg_buf;
	void *p = monhdr + 1;
	void *end = msg_buf + msg_len;
	int ret;

	monhdr->have_version = 0;
	monhdr->session_mon = cpu_to_le16(-1);
	monhdr->session_mon_tid = 0;

	ceph_encode_32(&p, ac->protocol);

	ret = ac->ops->build_request(ac, p + sizeof(u32), end);
	if (ret < 0) {
		pr_err("error %d building request\n", ret);
		return ret;
	}
	dout(" built request %d bytes\n", ret);
	ceph_encode_32(&p, ret);
	return p + ret - msg_buf;
}
コード例 #14
0
ファイル: auth.c プロジェクト: A2109devs/lenovo_a2109a_kernel
/*
 * Initiate protocol negotiation with monitor.  Include entity name
 * and list supported protocols.
 */
int ceph_auth_build_hello(struct ceph_auth_client *ac, void *buf, size_t len)
{
	struct ceph_mon_request_header *monhdr = buf;
	void *p = monhdr + 1, *end = buf + len, *lenp;
	int i, num;
	int ret;

	dout("auth_build_hello\n");
	monhdr->have_version = 0;
	monhdr->session_mon = cpu_to_le16(-1);
	monhdr->session_mon_tid = 0;

	ceph_encode_32(&p, 0);  /* no protocol, yet */

	lenp = p;
	p += sizeof(u32);

	ceph_decode_need(&p, end, 1 + sizeof(u32), bad);
	ceph_encode_8(&p, 1);
	num = ARRAY_SIZE(supported_protocols);
	ceph_encode_32(&p, num);
	ceph_decode_need(&p, end, num * sizeof(u32), bad);
	for (i = 0; i < num; i++)
		ceph_encode_32(&p, supported_protocols[i]);

	ret = ceph_entity_name_encode(ac->name, &p, end);
	if (ret < 0)
		return ret;
	ceph_decode_need(&p, end, sizeof(u64), bad);
	ceph_encode_64(&p, ac->global_id);

	ceph_encode_32(&lenp, p - lenp - sizeof(u32));
	return p - buf;

bad:
	return -ERANGE;
}
コード例 #15
0
ファイル: lm_sam.c プロジェクト: Makarevich/lsamod-digest
static int ondata_no_sid(struct lm_sam_s *This, PUNICODE_STRING uname, HASH hash, NTSTATUS *result){
    LSA_HANDLE                      h_policy;
    LSA_OBJECT_ATTRIBUTES           objattr;
    POLICY_ACCOUNT_DOMAIN_INFO      *pdomain_info;
    NTSTATUS                        status;
    char                            dname[64];

    memset(&objattr, 0, sizeof(objattr));
    objattr.Length = sizeof(objattr);

    if((status = LsaOpenPolicy(NULL, &objattr, POLICY_VIEW_LOCAL_INFORMATION, &h_policy)) != STATUS_SUCCESS){
        DOUTST2("LsaOpenPolicy", status);
        *result = status;
        return 0;
    }

    if((status = LsaQueryInformationPolicy(h_policy, PolicyAccountDomainInformation, &pdomain_info)) != STATUS_SUCCESS){
        DOUTST2("LsaQueryInformationPolicy", status);
        LsaClose(h_policy);
        *result = status;
        return 0;
    }

    if(unicode2ansi(pdomain_info->DomainName.Buffer, pdomain_info->DomainName.Length, dname, sizeof(dname)) == 0){
        strcpy(dname, "<unknown>");
    }

    dout(va("Current domain is %s.\n", dname));

    This->lsa_policy_info_buffer = pdomain_info;
    This->domain_sid = pdomain_info->DomainSid;

    // delegate processing to no_sam state
    This->state = &state_no_sam;
    return This->state->data(This, uname, hash, result);
}
コード例 #16
0
/*
 * osd map
 */
void ceph_osdmap_destroy(struct ceph_osdmap *map)
{
	dout("osdmap_destroy %p\n", map);
	if (map->crush)
		crush_destroy(map->crush);
	while (!RB_EMPTY_ROOT(&map->pg_temp)) {
		struct ceph_pg_mapping *pg =
			rb_entry(rb_first(&map->pg_temp),
				 struct ceph_pg_mapping, node);
		rb_erase(&pg->node, &map->pg_temp);
		kfree(pg);
	}
	while (!RB_EMPTY_ROOT(&map->pg_pools)) {
		struct ceph_pg_pool_info *pi =
			rb_entry(rb_first(&map->pg_pools),
				 struct ceph_pg_pool_info, node);
		rb_erase(&pi->node, &map->pg_pools);
		kfree(pi);
	}
	kfree(map->osd_state);
	kfree(map->osd_weight);
	kfree(map->osd_addr);
	kfree(map);
}
コード例 #17
0
ファイル: kqueuer.cpp プロジェクト: pp7462-git/sandbox
StateResult handle_client(void* arg) {
	Handler* handler = (Handler*) arg;
	IoResult ior;

	if (kresult == NULL) {
		migrate_state(handler, handle_client_cleanup);
		if (kmgr->enqueue_pevent(handler) < 0) {
			eout("[%d]: %s failed to enqueue pevent.\n", mypid, __FUNCTION__);
			return STATE_ERROR;
		}
		dout(2, "[%d]: %s done.\n", mypid, __FUNCTION__);
		return STATE_OKAY;
	}

	switch (kresult->filter) {
	case EVFILT_READ:
		dout(2, "[%d]: %s got EVFILT_READ...\n", mypid, __FUNCTION__);
		ior = client_read(handler);
		break;
	case EVFILT_WRITE:
		dout(2, "[%d]: %s got EVFILT_WRITE...\n", mypid, __FUNCTION__);
		ior = client_write(handler);
		break;
	default:
		dout(2, "[%d]: %s got unknown filter (%d); closing up shop.\n",
			mypid, __FUNCTION__, kresult->filter);
		ior = IO_ERROR;
	}

	if (ior < 0) {
		dout(2, "[%d]: %s got ior %d; close socket.\n", mypid, __FUNCTION__,
			ior);
		close(handler->fd);
		migrate_state(handler, handle_client_cleanup);
	}

	dout(2, "[%d]: %s done.\n", mypid, __FUNCTION__);
	return STATE_OKAY;
}
コード例 #18
0
ファイル: dtls_dispatch.cpp プロジェクト: karlpilkington/snow
void dtls_dispatch::snow_port_detect_packet(snow_port_detect* packet, vnet_peer& frompeer)
{
	const sockaddrunion& fromaddr = frompeer.conn->get_peer();
	if(packet->port == 0) {
		try {
			csocket test(fromaddr.s.sa_family, SOCK_DGRAM);
			test.connect(fromaddr);
			sockaddrunion local;
			test.getsockname(local);
			local.set_ip_port(local.s.sa_family == AF_INET ? htons(snow::conf[snow::DTLS_BIND_PORT]) : htons(snow::conf[snow::DTLS_BIND6_PORT]));
			auto local_it = socket_map.find(ip_info(local));
			if(local_it != socket_map.end()) {
				sockets[local_it->second].sock.sendto(packet->data, sizeof(packet->data), fromaddr);
				dout() << "Sent port detect UDP nonce to peer at " << fromaddr;
			} else {
				// this happening is probably a bug, there should be a socket on every local address that the OS would use for an outgoing packet
				dout() << "No socket found on " << local << " to send port detect nonce to " << fromaddr;
			}
		} catch(const e_check_sock_err& e) {
			dout() << "Could not send port detect UDP nonce packet to peer at " << fromaddr << ": " << e;
		}
	} else {
		ip_info ip(packet->data, packet->port);
		// zero port means we don't know the port (this also prevents the peer from adding multiple addrs/ports, as the first packet sets the port to nonzero)
		if(frompeer.visible_ipaddr.port == 0) {
			if(frompeer.visible_ipaddr.addr == ip.addr) {
				dout() << "Got port detect from " << fromaddr << " with addr " << ip;
				frompeer.visible_ipaddr.port = ip.port;
				add_peer_visible_ipaddr(ip);
			} else {
				// TODO: in theory an address different than the one provided in snow hello could provide useful information (e.g. some kind of enterprise NAT)
					// but it could also be some kind of attack, so discard addr for now and maybe revisit this later
				dout() << "Discarded port detect from " << fromaddr << " with addr " << ip << " which did not match expected address " << frompeer.visible_ipaddr.addr;
			}
		} else {
			dout() << "Discarded port detect from " << fromaddr << " with addr " << ip << " because existing addr and port were previously discovered as " << frompeer.visible_ipaddr;
		}
	}
}
コード例 #19
0
ファイル: debug.cpp プロジェクト: SirScarfalot/Cataclysm-DDA
void limitDebugLevel( int i )
{
 dout() << "Set debug level to: " << (DebugLevel)i;
 debugLevel = i;
}
コード例 #20
0
ファイル: mp_Regcomp.C プロジェクト: mfrosenberg68/WorkRegOld
int main()
{
  mp_init();

  //  const mp_complex I = mp_complex(0.0,1.0);

  static mp_real pi  = mppic;
  static mp_real pi2 = mppic * mppic;

  static mp_real Sqrtpi = sqrt(mppic);
  
  cout  << setiosflags(ios::uppercase);

  ofstream out("REGSOLC.out");
  out << setiosflags(ios::uppercase);

  ofstream kout("KERNELCMP.out");
  kout << setiosflags(ios::uppercase);
  
  ofstream dout("DATACMP.out");
  dout << setiosflags(ios::uppercase);
  
  int M, N;
  double bd;
  double x1d, x2d, xad, xbd;
  
  cin >> bd;
  cin >> xad >> xbd >> N;
  cin >> x1d >> x2d >> M;

  cout << "*** Precision = " << mpipl << " ***" << endl;
  cout << "b  = " << bd << endl;
  cout << "xa = " << xad << endl;
  cout << "xb = " << xbd << endl;
  cout << "x1 = " << x1d << endl;
  cout << "x2 = " << x2d << endl;
  cout << "N  = " << N << endl;
  cout << "M  = " << M << endl;

  mp_real xa   = mp_real(xad);
  mp_real xb   = mp_real(xbd);
  mp_real x1   = mp_real(x1d);
  mp_real x2   = mp_real(x2d);
  mp_real  b   = mp_real(bd);

  mp_real factor;
  factor = b/power(pi,mp_real(1.5))*exp(mp_real(1.25)*pi2*b*b);


  mp_real h    = (xb - xa)/mp_real(N);
  cout << "h  = " << h ;

  mp_real step = (x2 - x1)/mp_real(M);
  cout << "h2 = " << step;

  cout << "Faktor = " << factor << endl;


  mp_real mpx0; 
  //  mp_real mpx, mpx0; 
  //  mp_complex regkern, data;
  //  double Realregkern, Imaregkern;
  //  double RealData, ImaData;
  /*
  cout << " *** write Kernel and Data *** " << endl;
  
  for(int i = 0; i <= N; i++)
    {
      mpx0 = mp_real(0.0);
      mpx = xa + i * h;
      regkern = mpregkernc(mpx,mpx0,b);
      //      cout << mpx << regkern << endl;

      Realregkern = dble(MP_REAL(regkern));
      Imaregkern  = dble(aimag(regkern));

      //      data = E_data(mpx);
      //      cout << mpx << data << endl;

      //      RealData = dble(MP_REAL(data));
      //      ImaData  = dble(aimag(data));

      kout << dble(mpx) << '\t' << Realregkern << '\t' << Imaregkern << '\t' << bd<< endl;

      //      dout << dble(mpx) << '\t' << RealData << '\t' << ImaData << endl;
    }
    */
  mp_complex mpregsum;
  mp_real mpReg, RelError;
  double RealReg, ImaReg, Error;

  cout << " *** Begin: Regularisation *** " << endl;

  for(int j = 0; j <= M; j++)
    {
      mpx0 = x1 + j * step;

      mpregsum = mptrapez(RegIntegrand,mpx0,b,mpx0,.5*h,N);
      mpregsum *=factor;

      mpReg = Regtheo(mpx0,b);
      RelError = abs(mpregsum - mpReg)/abs(mpReg);
      RelError *= mp_real(100.0);

      cout << mpx0 << mpregsum  << endl;
      cout << mpReg << RelError << endl;
      
      RealReg = dble(MP_REAL(mpregsum));
      ImaReg  = dble(aimag(mpregsum));
      Error   = dble(RelError);

      out << dble(mpx0) << '\t' << dble(mpReg) << '\t' << RealReg << '\t' << ImaReg << '\t' << Error << '\t' << bd << endl;
    }
  cout << " *** End: Regularisation *** " << endl;
  
  return 0;
}
コード例 #21
0
static struct crush_map *crush_decode(void *pbyval, void *end)
{
	struct crush_map *c;
	int err = -EINVAL;
	int i, j;
	void **p = &pbyval;
	void *start = pbyval;
	u32 magic;

	dout("crush_decode %p to %p len %d\n", *p, end, (int)(end - *p));

	c = kzalloc(sizeof(*c), GFP_NOFS);
	if (c == NULL)
		return ERR_PTR(-ENOMEM);

	ceph_decode_need(p, end, 4*sizeof(u32), bad);
	magic = ceph_decode_32(p);
	if (magic != CRUSH_MAGIC) {
		pr_err("crush_decode magic %x != current %x\n",
		       (unsigned)magic, (unsigned)CRUSH_MAGIC);
		goto bad;
	}
	c->max_buckets = ceph_decode_32(p);
	c->max_rules = ceph_decode_32(p);
	c->max_devices = ceph_decode_32(p);

	c->device_parents = kcalloc(c->max_devices, sizeof(u32), GFP_NOFS);
	if (c->device_parents == NULL)
		goto badmem;
	c->bucket_parents = kcalloc(c->max_buckets, sizeof(u32), GFP_NOFS);
	if (c->bucket_parents == NULL)
		goto badmem;

	c->buckets = kcalloc(c->max_buckets, sizeof(*c->buckets), GFP_NOFS);
	if (c->buckets == NULL)
		goto badmem;
	c->rules = kcalloc(c->max_rules, sizeof(*c->rules), GFP_NOFS);
	if (c->rules == NULL)
		goto badmem;

	/* buckets */
	for (i = 0; i < c->max_buckets; i++) {
		int size = 0;
		u32 alg;
		struct crush_bucket *b;

		ceph_decode_32_safe(p, end, alg, bad);
		if (alg == 0) {
			c->buckets[i] = NULL;
			continue;
		}
		dout("crush_decode bucket %d off %x %p to %p\n",
		     i, (int)(*p-start), *p, end);

		switch (alg) {
		case CRUSH_BUCKET_UNIFORM:
			size = sizeof(struct crush_bucket_uniform);
			break;
		case CRUSH_BUCKET_LIST:
			size = sizeof(struct crush_bucket_list);
			break;
		case CRUSH_BUCKET_TREE:
			size = sizeof(struct crush_bucket_tree);
			break;
		case CRUSH_BUCKET_STRAW:
			size = sizeof(struct crush_bucket_straw);
			break;
		default:
			err = -EINVAL;
			goto bad;
		}
		BUG_ON(size == 0);
		b = c->buckets[i] = kzalloc(size, GFP_NOFS);
		if (b == NULL)
			goto badmem;

		ceph_decode_need(p, end, 4*sizeof(u32), bad);
		b->id = ceph_decode_32(p);
		b->type = ceph_decode_16(p);
		b->alg = ceph_decode_8(p);
		b->hash = ceph_decode_8(p);
		b->weight = ceph_decode_32(p);
		b->size = ceph_decode_32(p);

		dout("crush_decode bucket size %d off %x %p to %p\n",
		     b->size, (int)(*p-start), *p, end);

		b->items = kcalloc(b->size, sizeof(__s32), GFP_NOFS);
		if (b->items == NULL)
			goto badmem;
		b->perm = kcalloc(b->size, sizeof(u32), GFP_NOFS);
		if (b->perm == NULL)
			goto badmem;
		b->perm_n = 0;

		ceph_decode_need(p, end, b->size*sizeof(u32), bad);
		for (j = 0; j < b->size; j++)
			b->items[j] = ceph_decode_32(p);

		switch (b->alg) {
		case CRUSH_BUCKET_UNIFORM:
			err = crush_decode_uniform_bucket(p, end,
				  (struct crush_bucket_uniform *)b);
			if (err < 0)
				goto bad;
			break;
		case CRUSH_BUCKET_LIST:
			err = crush_decode_list_bucket(p, end,
			       (struct crush_bucket_list *)b);
			if (err < 0)
				goto bad;
			break;
		case CRUSH_BUCKET_TREE:
			err = crush_decode_tree_bucket(p, end,
				(struct crush_bucket_tree *)b);
			if (err < 0)
				goto bad;
			break;
		case CRUSH_BUCKET_STRAW:
			err = crush_decode_straw_bucket(p, end,
				(struct crush_bucket_straw *)b);
			if (err < 0)
				goto bad;
			break;
		}
	}

	/* rules */
	dout("rule vec is %p\n", c->rules);
	for (i = 0; i < c->max_rules; i++) {
		u32 yes;
		struct crush_rule *r;

		ceph_decode_32_safe(p, end, yes, bad);
		if (!yes) {
			dout("crush_decode NO rule %d off %x %p to %p\n",
			     i, (int)(*p-start), *p, end);
			c->rules[i] = NULL;
			continue;
		}

		dout("crush_decode rule %d off %x %p to %p\n",
		     i, (int)(*p-start), *p, end);

		/* len */
		ceph_decode_32_safe(p, end, yes, bad);
#if BITS_PER_LONG == 32
		err = -EINVAL;
		if (yes > ULONG_MAX / sizeof(struct crush_rule_step))
			goto bad;
#endif
		r = c->rules[i] = kmalloc(sizeof(*r) +
					  yes*sizeof(struct crush_rule_step),
					  GFP_NOFS);
		if (r == NULL)
			goto badmem;
		dout(" rule %d is at %p\n", i, r);
		r->len = yes;
		ceph_decode_copy_safe(p, end, &r->mask, 4, bad); /* 4 u8's */
		ceph_decode_need(p, end, r->len*3*sizeof(u32), bad);
		for (j = 0; j < r->len; j++) {
			r->steps[j].op = ceph_decode_32(p);
			r->steps[j].arg1 = ceph_decode_32(p);
			r->steps[j].arg2 = ceph_decode_32(p);
		}
	}

	/* ignore trailing name maps. */

	dout("crush_decode success\n");
	return c;

badmem:
	err = -ENOMEM;
bad:
	dout("crush_decode fail %d\n", err);
	crush_destroy(c);
	return ERR_PTR(err);
}
コード例 #22
0
ファイル: CbkSemaphore.cpp プロジェクト: x-itec/oldercrap
void CbkSemaphore::V()
{
dout(CbkBase::LM_CORE,"Sem-V");
pv(1);
}
コード例 #23
0
ファイル: mdsmap.c プロジェクト: 513855417/linux
/*
 * Decode an MDS map
 *
 * Ignore any fields we don't care about (there are quite a few of
 * them).
 */
struct ceph_mdsmap *ceph_mdsmap_decode(void **p, void *end)
{
	struct ceph_mdsmap *m;
	const void *start = *p;
	int i, j, n;
	int err = -EINVAL;
	u8 mdsmap_v, mdsmap_cv;

	m = kzalloc(sizeof(*m), GFP_NOFS);
	if (m == NULL)
		return ERR_PTR(-ENOMEM);

	ceph_decode_need(p, end, 1 + 1, bad);
	mdsmap_v = ceph_decode_8(p);
	mdsmap_cv = ceph_decode_8(p);
	if (mdsmap_v >= 4) {
	       u32 mdsmap_len;
	       ceph_decode_32_safe(p, end, mdsmap_len, bad);
	       if (end < *p + mdsmap_len)
		       goto bad;
	       end = *p + mdsmap_len;
	}

	ceph_decode_need(p, end, 8*sizeof(u32) + sizeof(u64), bad);
	m->m_epoch = ceph_decode_32(p);
	m->m_client_epoch = ceph_decode_32(p);
	m->m_last_failure = ceph_decode_32(p);
	m->m_root = ceph_decode_32(p);
	m->m_session_timeout = ceph_decode_32(p);
	m->m_session_autoclose = ceph_decode_32(p);
	m->m_max_file_size = ceph_decode_64(p);
	m->m_max_mds = ceph_decode_32(p);

	m->m_info = kcalloc(m->m_max_mds, sizeof(*m->m_info), GFP_NOFS);
	if (m->m_info == NULL)
		goto badmem;

	/* pick out active nodes from mds_info (state > 0) */
	n = ceph_decode_32(p);
	for (i = 0; i < n; i++) {
		u64 global_id;
		u32 namelen;
		s32 mds, inc, state;
		u64 state_seq;
		u8 info_v;
		void *info_end = NULL;
		struct ceph_entity_addr addr;
		u32 num_export_targets;
		void *pexport_targets = NULL;
		struct ceph_timespec laggy_since;
		struct ceph_mds_info *info;

		ceph_decode_need(p, end, sizeof(u64) + 1, bad);
		global_id = ceph_decode_64(p);
		info_v= ceph_decode_8(p);
		if (info_v >= 4) {
			u32 info_len;
			u8 info_cv;
			ceph_decode_need(p, end, 1 + sizeof(u32), bad);
			info_cv = ceph_decode_8(p);
			info_len = ceph_decode_32(p);
			info_end = *p + info_len;
			if (info_end > end)
				goto bad;
		}

		ceph_decode_need(p, end, sizeof(u64) + sizeof(u32), bad);
		*p += sizeof(u64);
		namelen = ceph_decode_32(p);  /* skip mds name */
		*p += namelen;

		ceph_decode_need(p, end,
				 4*sizeof(u32) + sizeof(u64) +
				 sizeof(addr) + sizeof(struct ceph_timespec),
				 bad);
		mds = ceph_decode_32(p);
		inc = ceph_decode_32(p);
		state = ceph_decode_32(p);
		state_seq = ceph_decode_64(p);
		ceph_decode_copy(p, &addr, sizeof(addr));
		ceph_decode_addr(&addr);
		ceph_decode_copy(p, &laggy_since, sizeof(laggy_since));
		*p += sizeof(u32);
		ceph_decode_32_safe(p, end, namelen, bad);
		*p += namelen;
		if (info_v >= 2) {
			ceph_decode_32_safe(p, end, num_export_targets, bad);
			pexport_targets = *p;
			*p += num_export_targets * sizeof(u32);
		} else {
			num_export_targets = 0;
		}

		if (info_end && *p != info_end) {
			if (*p > info_end)
				goto bad;
			*p = info_end;
		}

		dout("mdsmap_decode %d/%d %lld mds%d.%d %s %s\n",
		     i+1, n, global_id, mds, inc,
		     ceph_pr_addr(&addr.in_addr),
		     ceph_mds_state_name(state));

		if (mds < 0 || mds >= m->m_max_mds || state <= 0)
			continue;

		info = &m->m_info[mds];
		info->global_id = global_id;
		info->state = state;
		info->addr = addr;
		info->laggy = (laggy_since.tv_sec != 0 ||
			       laggy_since.tv_nsec != 0);
		info->num_export_targets = num_export_targets;
		if (num_export_targets) {
			info->export_targets = kcalloc(num_export_targets,
						       sizeof(u32), GFP_NOFS);
			if (info->export_targets == NULL)
				goto badmem;
			for (j = 0; j < num_export_targets; j++)
				info->export_targets[j] =
				       ceph_decode_32(&pexport_targets);
		} else {
			info->export_targets = NULL;
		}
	}

	/* pg_pools */
	ceph_decode_32_safe(p, end, n, bad);
	m->m_num_data_pg_pools = n;
	m->m_data_pg_pools = kcalloc(n, sizeof(u64), GFP_NOFS);
	if (!m->m_data_pg_pools)
		goto badmem;
	ceph_decode_need(p, end, sizeof(u64)*(n+1), bad);
	for (i = 0; i < n; i++)
		m->m_data_pg_pools[i] = ceph_decode_64(p);
	m->m_cas_pg_pool = ceph_decode_64(p);

	/* ok, we don't care about the rest. */
	*p = end;
	dout("mdsmap_decode success epoch %u\n", m->m_epoch);
	return m;

badmem:
	err = -ENOMEM;
bad:
	pr_err("corrupt mdsmap\n");
	print_hex_dump(KERN_DEBUG, "mdsmap: ",
		       DUMP_PREFIX_OFFSET, 16, 1,
		       start, end - start, true);
	ceph_mdsmap_destroy(m);
	return ERR_PTR(err);
}
コード例 #24
0
ファイル: CbkSemaphore.cpp プロジェクト: x-itec/oldercrap
CbkSemaphore::~CbkSemaphore()
{
dout(CbkBase::LM_CORE,"Semaphore Destruktor");
semctl(semid,IPC_RMID,0);
}
コード例 #25
0
ファイル: CbkSemaphore.cpp プロジェクト: x-itec/oldercrap
void CbkSemaphore::P()
{
dout(CbkBase::LM_CORE,"Sem-P");
pv(-1);
}
コード例 #26
0
int main()
{
  cout  << setiosflags(ios::uppercase);
  ofstream out("GAUSS.out");
  out   << setiosflags(ios::uppercase);
  ofstream dout("GAUSSMOD.out");
  dout  << setiosflags(ios::uppercase);

  mp_init();
  double s_in, h_in , b_in, dfactor, dpi, x1_in, x2_in;
  int N, m, Control;

  dpi = 4.0 * atan(1.0);
  
  mp_real pi = mppic; // pi aus der Bibliothek !!!
  mp_real pi2 = pi * pi;
  static mp_real factor;
  
  mp_real a, b, x0, s, h, x1, x2;

  /* Parameter als doubles einlesen */
  cin >> b_in >> Control;
  cin >> s_in >> h_in >> N;
  cin >> x1_in >> x2_in >> m;

  /* Konversion: double -> mp_real */
  b  = mp_real(b_in);
  s  = mp_real(s_in);
  h  = mp_real(h_in);
  x1 = mp_real(x1_in);
  x2 = mp_real(x2_in);
  a  = 1/(mp_real(2.0)*b);

  /* Vorfaktor */
  factor = mp_real(2.0)*b/power(pi,mp_real(1.5));
  factor *= exp(mp_real(0.25) * pi2 * b * b);
  
  dfactor = 2.0 * (b_in/pow(dpi,1.5)) * exp(b_in*b_in*dpi*dpi*.25);

  cout << "+++ Precision = " << mpipl << " +++" << endl;
  cout << "b  = " << b ;
  cout << "a  = " << a;
  cout << "h  = " << h;
  cout << "N  = " << N << endl;
  cout << '\v' ;
  cout << "x1 = " << x1;
  cout << "x2 = " << x2;
  cout << "m  = " << m << endl;
  
  cout << "xmax = " << h * N << endl;
  
  cout << "dfaktor = " <<dfactor << endl;
  cout << "Faktor = " <<factor << endl;
  
  mp_real mp_E2_Gauss, mp_E2_Gausstheo, mp_Reg, mp_Regtheo, mp_ModGauss, step;
  mp_real mp_diffrel, mp_diffrelreg;
  double E2, E2_Gauss, E2_Gausstheo, Reg, Reg_theod, ModGauss, diffrel, x0d;
  double diffrelreg;
  
  step = (x2 -x1)/mp_real(m);


  if(Control == 1)
    {
	cout << "*** Begin: Read Data ***" << endl; 
      for(int j = 0; j <= m; j++)
	{
	  x0 = x1 + j * step; 
	  mp_E2_Gauss = mpe2gauss(x0);
	  mp_E2_Gausstheo = mpe2gausstheo(x0);
	  mp_real mpdeltarel = abs(mp_E2_Gauss - mp_E2_Gausstheo)/abs(mp_E2_Gausstheo);
	  mpdeltarel *= mp_real(100.0);
	  
	  x0d = dble(x0);
	  E2 = e2(x0d);
	  E2_Gauss        = dble(mp_E2_Gauss);
	  E2_Gausstheo    = dble(mp_E2_Gausstheo);
	  double deltarel = dble(mpdeltarel);
	  cout << x0 << mp_E2_Gausstheo << mp_E2_Gauss << mpdeltarel << endl;;

	  (ostream&) dout << x0d << '\t' << E2 << '\t' << E2_Gausstheo <<'\t' << E2_Gauss << '\t' << deltarel << endl;
      	}
      cout << "*** End: Read Data ***" << endl; 
    }

  cout << "*** Begin: Regularisation ***" << endl;
  for(int jj = 0; jj <= m; jj++)
    {
      x0 = x1 + jj * step;
      s = x0;
      mp_Reg = mptrapez(mpkern,x0,b,s,h,N);
      mp_Reg *= factor;
  
      mp_Regtheo  = Regtheo(x0, a); //reine Regularisierte
      mp_ModGauss = GaussDichte(x0); //Gaussdichte als Modell
      
      
      mp_diffrel = abs(mp_Reg - mp_Regtheo)/abs(mp_Regtheo);
      mp_diffrel *= mp_real(100.0);
      
      mp_diffrelreg  = abs(mp_Reg - mp_ModGauss)/abs(mp_ModGauss);
      mp_diffrelreg *= mp_real(100.0);

      Reg_theod  = dble(mp_Regtheo);
      Reg        = dble(mp_Reg);
      ModGauss   = dble(mp_ModGauss);
      diffrel    = dble(mp_diffrel);
      diffrelreg = dble(mp_diffrelreg);
      x0d        = dble(x0);

      cout << mp_Reg << mp_Regtheo << mp_ModGauss << mp_diffrel << mp_diffrelreg<< endl;
      
      (ostream&) out << b_in << '\t' << x0d << '\t' << ModGauss << '\t' << Reg << '\t' << Reg_theod<< '\t' << diffrel <<'\t' << diffrelreg << endl;
      
    }
  cout << "*** End: Regularisation ***" << endl;
  return 0;
}
コード例 #27
0
ファイル: main.cpp プロジェクト: CRS-ECHO51/supertux
int main(int argc, char** argv)
{
    std::string outputcpp;
    std::string outputhpp;
    std::string output_doc;
    for(int i = 0; i < argc; ++i) {
        if(strcmp(argv[i], "--module") == 0) {
            if(i+1 >= argc) {
                std::cerr << "Need to specify a module name.\n";
                usage();
                return 1;
            }
            modulename = argv[++i];
        } else if(strcmp(argv[i], "--input") == 0) {
            if(i+1 >= argc) {
                std::cerr << "Need to specify input file name.\n";
                usage();
                return 1;
            }
            inputfile = argv[++i];
        } else if(strcmp(argv[i], "--output-cpp") == 0) {
            if(i+1 >= argc) {
                std::cerr << "Need to specify output cpp name.\n";
                usage();
                return 1;
            }
            outputcpp = argv[++i];
        } else if(strcmp(argv[i], "--output-hpp") == 0) {
            if(i+1 >= argc) {
                std::cerr << "Need to specify output hpp name.\n";
                usage();
                return 1;
            }
            outputhpp = argv[++i];
        } else if(strcmp(argv[i], "--select-namespace") == 0) {
            if(i+1 >= argc) {
                std::cerr << "Need to specify a namespace.\n";
                usage();
                return 1;
            }
            selected_namespace = argv[++i];
        } else if(strcmp(argv[i], "--output-doc") == 0) {
          if(i+1 >= argc) {
            std::cerr << "Need to specify document xml file.\n";
            usage();
            return 1;
          }
          output_doc = argv[++i];
        } else if(argv[i][0] == '-') {
            std::cerr << "Unknown option '" << argv[i] << "'.\n";
            usage();
            return 1;
        } else {
        }
    }
    if( inputfile == "" || (
            (outputcpp == "" || outputhpp == "") && output_doc == "")) {
        std::cerr << "Not all options specified.\n";
        usage();
        return 1;
    }

    try {
        input = new std::ifstream(inputfile.c_str());
        if(!input->good()) {
            std::cerr << "Couldn't open file '" << inputfile << "' for reading.\n";
            return 1;
        }
        current_file = inputfile;
        unit = new CompilationUnit();
        Namespace* std_namespace = new Namespace();
        std_namespace->name = "std";
        std_namespace->types.push_back(new StringType());
        unit->namespaces.push_back(std_namespace);
        unit->types.push_back(new HSQUIRRELVMType());
        unit->types.push_back(new SQIntegerType());

        yyparse();

        Namespace* ns = unit;
        if(selected_namespace != "") {
            ns = ns->findNamespace(selected_namespace);
        }

        if(outputcpp != "") {
            std::ofstream cppout(outputcpp.c_str());
            if(!cppout.good()) {
                std::cerr << "Couldn't open file '"
                          << outputcpp << "' for writing.\n";
                return 1;
            }
            std::ofstream hppout(outputhpp.c_str());
            if(!hppout.good()) {
                std::cerr << "Couldn't open file '" << outputhpp
                          << "' for writing.\n";
                return 1;
            }

            WrapperCreator creator(cppout, hppout);
            creator.create_wrapper(ns);
        }

        if(output_doc != "") {
            std::ofstream dout(output_doc.c_str());
            if(!dout.good()) {
                std::cerr << "Couldn't open file '"
                    << output_doc << "' for writing.\n";
                return 1;
            }
            DocuCreator creator(dout);
            creator.create_docu(ns);
        }
    } catch(std::exception& e) {
        std::cerr << "Exception: " << e.what() << "\n";
        return 1;
    }

    return 0;
}
コード例 #28
0
ファイル: debug.cpp プロジェクト: SirScarfalot/Cataclysm-DDA
void limitDebugClass( int i )
{
 dout() << "Set debug class to: " << (DebugClass)i;
 debugClass = i;
}
コード例 #29
0
ファイル: file.c プロジェクト: Smackbox/linux-2.6-sgt
/*
 * If the filp already has private_data, that means the file was
 * already opened by intent during lookup, and we do nothing.
 *
 * If we already have the requisite capabilities, we can satisfy
 * the open request locally (no need to request new caps from the
 * MDS).  We do, however, need to inform the MDS (asynchronously)
 * if our wanted caps set expands.
 */
int ceph_open(struct inode *inode, struct file *file)
{
	struct ceph_inode_info *ci = ceph_inode(inode);
	struct ceph_fs_client *fsc = ceph_sb_to_client(inode->i_sb);
	struct ceph_mds_client *mdsc = fsc->mdsc;
	struct ceph_mds_request *req;
	struct ceph_file_info *cf = file->private_data;
	struct inode *parent_inode = file->f_dentry->d_parent->d_inode;
	int err;
	int flags, fmode, wanted;

	if (cf) {
		dout("open file %p is already opened\n", file);
		return 0;
	}

	/* filter out O_CREAT|O_EXCL; vfs did that already.  yuck. */
	flags = file->f_flags & ~(O_CREAT|O_EXCL);
	if (S_ISDIR(inode->i_mode))
		flags = O_DIRECTORY;  /* mds likes to know */

	dout("open inode %p ino %llx.%llx file %p flags %d (%d)\n", inode,
	     ceph_vinop(inode), file, flags, file->f_flags);
	fmode = ceph_flags_to_mode(flags);
	wanted = ceph_caps_for_mode(fmode);

	/* snapped files are read-only */
	if (ceph_snap(inode) != CEPH_NOSNAP && (file->f_mode & FMODE_WRITE))
		return -EROFS;

	/* trivially open snapdir */
	if (ceph_snap(inode) == CEPH_SNAPDIR) {
		spin_lock(&inode->i_lock);
		__ceph_get_fmode(ci, fmode);
		spin_unlock(&inode->i_lock);
		return ceph_init_file(inode, file, fmode);
	}

	/*
	 * No need to block if we have caps on the auth MDS (for
	 * write) or any MDS (for read).  Update wanted set
	 * asynchronously.
	 */
	spin_lock(&inode->i_lock);
	if (__ceph_is_any_real_caps(ci) &&
	    (((fmode & CEPH_FILE_MODE_WR) == 0) || ci->i_auth_cap)) {
		int mds_wanted = __ceph_caps_mds_wanted(ci);
		int issued = __ceph_caps_issued(ci, NULL);

		dout("open %p fmode %d want %s issued %s using existing\n",
		     inode, fmode, ceph_cap_string(wanted),
		     ceph_cap_string(issued));
		__ceph_get_fmode(ci, fmode);
		spin_unlock(&inode->i_lock);

		/* adjust wanted? */
		if ((issued & wanted) != wanted &&
		    (mds_wanted & wanted) != wanted &&
		    ceph_snap(inode) != CEPH_SNAPDIR)
			ceph_check_caps(ci, 0, NULL);

		return ceph_init_file(inode, file, fmode);
	} else if (ceph_snap(inode) != CEPH_NOSNAP &&
		   (ci->i_snap_caps & wanted) == wanted) {
		__ceph_get_fmode(ci, fmode);
		spin_unlock(&inode->i_lock);
		return ceph_init_file(inode, file, fmode);
	}
	spin_unlock(&inode->i_lock);

	dout("open fmode %d wants %s\n", fmode, ceph_cap_string(wanted));
	req = prepare_open_request(inode->i_sb, flags, 0);
	if (IS_ERR(req)) {
		err = PTR_ERR(req);
		goto out;
	}
	req->r_inode = igrab(inode);
	req->r_num_caps = 1;
	err = ceph_mdsc_do_request(mdsc, parent_inode, req);
	if (!err)
		err = ceph_init_file(inode, file, req->r_fmode);
	ceph_mdsc_put_request(req);
	dout("open result=%d on %llx.%llx\n", err, ceph_vinop(inode));
out:
	return err;
}
コード例 #30
0
ファイル: file.c プロジェクト: Smackbox/linux-2.6-sgt
/*
 * Read a range of bytes striped over one or more objects.  Iterate over
 * objects we stripe over.  (That's not atomic, but good enough for now.)
 *
 * If we get a short result from the OSD, check against i_size; we need to
 * only return a short read to the caller if we hit EOF.
 */
static int striped_read(struct inode *inode,
			u64 off, u64 len,
			struct page **pages, int num_pages,
			int *checkeof, bool align_to_pages)
{
	struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
	struct ceph_inode_info *ci = ceph_inode(inode);
	u64 pos, this_len;
	int io_align, page_align;
	int page_off = off & ~PAGE_CACHE_MASK; /* first byte's offset in page */
	int left, pages_left;
	int read;
	struct page **page_pos;
	int ret;
	bool hit_stripe, was_short;

	/*
	 * we may need to do multiple reads.  not atomic, unfortunately.
	 */
	pos = off;
	left = len;
	page_pos = pages;
	pages_left = num_pages;
	read = 0;
	io_align = off & ~PAGE_MASK;

more:
	if (align_to_pages)
		page_align = (pos - io_align) & ~PAGE_MASK;
	else
		page_align = pos & ~PAGE_MASK;
	this_len = left;
	ret = ceph_osdc_readpages(&fsc->client->osdc, ceph_vino(inode),
				  &ci->i_layout, pos, &this_len,
				  ci->i_truncate_seq,
				  ci->i_truncate_size,
				  page_pos, pages_left, page_align);
	hit_stripe = this_len < left;
	was_short = ret >= 0 && ret < this_len;
	if (ret == -ENOENT)
		ret = 0;
	dout("striped_read %llu~%u (read %u) got %d%s%s\n", pos, left, read,
	     ret, hit_stripe ? " HITSTRIPE" : "", was_short ? " SHORT" : "");

	if (ret > 0) {
		int didpages =
			((pos & ~PAGE_CACHE_MASK) + ret) >> PAGE_CACHE_SHIFT;

		if (read < pos - off) {
			dout(" zero gap %llu to %llu\n", off + read, pos);
			ceph_zero_page_vector_range(page_off + read,
						    pos - off - read, pages);
		}
		pos += ret;
		read = pos - off;
		left -= ret;
		page_pos += didpages;
		pages_left -= didpages;

		/* hit stripe? */
		if (left && hit_stripe)
			goto more;
	}