コード例 #1
0
ファイル: flocklocks.c プロジェクト: JoeTime17/moosefs
uint8_t flock_mr_change(uint32_t inode,uint32_t sessionid,uint64_t owner,char cmd) {
	inodelocks *il;
	lock *l,*nl;
	uint8_t ltype;

	if (cmd=='U' || cmd=='u') {
		il = flock_inode_find(inode);
		if (il==NULL) {
			return MFS_ERROR_MISMATCH;
		}
		l=il->active;
		while (l) {
			nl = l->next;
			if (l->sessionid==sessionid && l->owner==owner) {
				flock_do_lock_remove(l);
				meta_version_inc();
			}
			l = nl;
		}
		if (il->waiting_head==NULL && il->active==NULL) {
			flock_inode_remove(il->inode);
		}
		return MFS_STATUS_OK;
	} else if (cmd=='R' || cmd=='r' || cmd=='S' || cmd=='s') {
		ltype = LTYPE_READER;
	} else if (cmd=='W' || cmd=='w' || cmd=='E' || cmd=='e') {
		ltype = LTYPE_WRITER;
	} else {
		return MFS_ERROR_EINVAL;
	}
	il = flock_inode_find(inode);
	if (il==NULL) {
		il = flock_inode_new(inode);
	}
	if (il->active!=NULL && (il->active->ltype==LTYPE_WRITER || ltype==LTYPE_WRITER)) {
		return MFS_ERROR_MISMATCH;
	}
	l = malloc(sizeof(lock));
	l->owner = owner;
	l->sessionid = sessionid;
	l->state = STATE_ACTIVE;
	l->ltype = ltype;
	l->lock_instances = NULL;
	l->parent = il;
	l->next = NULL;
	l->prev = NULL;
	flock_do_lock_inode_attach(l);
	meta_version_inc();
	return MFS_STATUS_OK;
}
コード例 #2
0
ファイル: changelog.c プロジェクト: JoeTime17/moosefs
void changelog(const char *format,...) {
	static char printbuff[MAXLOGLINESIZE];
	va_list ap;
	uint32_t leng;

	uint64_t version = meta_version_inc();

	va_start(ap,format);
	leng = vsnprintf(printbuff,MAXLOGLINESIZE,format,ap);
	va_end(ap);
	if (leng>=MAXLOGLINESIZE) {
		printbuff[MAXLOGLINESIZE-1]='\0';
		leng=MAXLOGLINESIZE;
	} else {
		leng++;
	}

	changelog_mr(version,printbuff);
//	if (currentfd==NULL) {
//		currentfd = fopen("changelog.0.mfs","a");
//		if (!currentfd) {
//			syslog(LOG_NOTICE,"lost MFS change %"PRIu64": %s",version,printbuff);
//		}
//	}
//
//	if (currentfd) {
//		fprintf(currentfd,"%"PRIu64": %s\n",version,printbuff);
//		fflush(currentfd);
//	}
	changelog_store_logstring(version,(uint8_t*)printbuff,leng);
}
コード例 #3
0
ファイル: storageclass.c プロジェクト: onlyjob/moosefs
static inline uint8_t sclass_univ_delete_entry(uint8_t nleng,const uint8_t *name,uint16_t esclassid) {
	uint32_t sclassid,fsclassid;
	if (sclass_name_check(nleng,name)==0) {
		return MFS_ERROR_EINVAL;
	}
	fsclassid = 0;
	for (sclassid=1 ; fsclassid==0 && sclassid<firstneverused ; sclassid++) {
		if (sclasstab[sclassid].nleng==nleng && memcmp(sclasstab[sclassid].name,name,nleng)==0) {
			fsclassid = sclassid;
		}
	}
	if (fsclassid==0) {
		return MFS_ERROR_NOSUCHCLASS;
	}
	if (fsclassid<FIRSTSCLASSID) {
		return MFS_ERROR_EPERM;
	}
	if (sclasstab[fsclassid].files>0 || sclasstab[fsclassid].directories>0) {
		return MFS_ERROR_CLASSINUSE;
	}
	if (esclassid!=0 && fsclassid!=esclassid) {
		return MFS_ERROR_MISMATCH;
	}
	sclasstab[fsclassid].nleng = 0;
	if (esclassid==0) {
		changelog("%"PRIu32"|SCDEL(%s):%"PRIu32,main_time(),changelog_escape_name(nleng,name),fsclassid);
	} else {
		meta_version_inc();
	}
	return MFS_STATUS_OK;
}
コード例 #4
0
ファイル: storageclass.c プロジェクト: onlyjob/moosefs
static inline uint8_t sclass_univ_rename_entry(uint8_t oldnleng,const uint8_t *oldname,uint8_t newnleng,const uint8_t *newname,uint16_t esclassid) {
	uint32_t sclassid,fsclassid;
	if (sclass_name_check(oldnleng,oldname)==0 || sclass_name_check(newnleng,newname)==0) {
		return MFS_ERROR_EINVAL;
	}
	fsclassid = 0;
	for (sclassid=1 ; fsclassid==0 && sclassid<firstneverused ; sclassid++) {
		if (sclasstab[sclassid].nleng==oldnleng && memcmp(sclasstab[sclassid].name,oldname,oldnleng)==0) {
			fsclassid = sclassid;
		}
	}
	if (fsclassid==0) {
		return MFS_ERROR_NOSUCHCLASS;
	}
	if (fsclassid<FIRSTSCLASSID) {
		return MFS_ERROR_EPERM;
	}
	if (esclassid!=0 && fsclassid!=esclassid) {
		return MFS_ERROR_MISMATCH;
	}
	for (sclassid=1 ; sclassid<firstneverused ; sclassid++) {
		if (sclasstab[sclassid].nleng==newnleng && memcmp(sclasstab[sclassid].name,newname,newnleng)==0) {
			return MFS_ERROR_CLASSEXISTS;
		}
	}
	sclasstab[fsclassid].nleng = newnleng;
	memcpy(sclasstab[fsclassid].name,newname,newnleng);
	if (esclassid==0) {
		changelog("%"PRIu32"|SCREN(%s,%s):%"PRIu32,main_time(),changelog_escape_name(oldnleng,oldname),changelog_escape_name(newnleng,newname),fsclassid);
	} else {
		meta_version_inc();
	}
	return MFS_STATUS_OK;
}
コード例 #5
0
ファイル: storageclass.c プロジェクト: onlyjob/moosefs
uint8_t sclass_mr_set_entry(uint8_t nleng,const uint8_t *name,uint16_t esclassid,uint8_t new_flag,uint8_t admin_only,uint8_t create_mode,uint8_t create_labelscnt,uint32_t *create_labelmasks,uint8_t keep_labelscnt,uint32_t *keep_labelmasks,uint8_t arch_labelscnt,uint32_t *arch_labelmasks,uint16_t arch_delay) {
	uint32_t sclassid,fsclassid;
	uint32_t i;
	if (sclass_name_check(nleng,name)==0) {
		return MFS_ERROR_EINVAL;
	}
	fsclassid = 0;
	for (sclassid=1 ; sclassid<firstneverused ; sclassid++) {
		if (sclasstab[sclassid].nleng==nleng && memcmp(sclasstab[sclassid].name,name,nleng)==0) {
			if (new_flag) {
				return MFS_ERROR_CLASSEXISTS;
			} else {
				fsclassid = sclassid;
				break;
			}
		}
		if (sclasstab[sclassid].nleng==0 && fsclassid==0 && new_flag) {
			fsclassid = sclassid;
		}
	}
	if (fsclassid==0) {
		if (new_flag) {
			if (firstneverused==MAXSCLASS) {
				return MFS_ERROR_CLASSLIMITREACH;
			}
			fsclassid = firstneverused;
			firstneverused++;
		} else {
			return MFS_ERROR_NOSUCHCLASS;
		}
	}
	if (fsclassid!=esclassid) {
		return MFS_ERROR_MISMATCH;
	}
	if (create_labelscnt==0 || create_labelscnt>MAXLABELSCNT || keep_labelscnt==0 || keep_labelscnt>MAXLABELSCNT || arch_labelscnt==0 || arch_labelscnt>MAXLABELSCNT) {
		return MFS_ERROR_EINVAL;
	}
	if (new_flag) {
		sclasstab[fsclassid].nleng = nleng;
		memcpy(sclasstab[fsclassid].name,name,nleng);
	}
	sclasstab[fsclassid].admin_only = admin_only;
	sclasstab[fsclassid].create_mode = create_mode;
	sclasstab[fsclassid].create_labelscnt = create_labelscnt;
	for (i=0 ; i<create_labelscnt ; i++) {
		memcpy(sclasstab[fsclassid].create_labelmasks[i],create_labelmasks+(i*MASKORGROUP),MASKORGROUP*sizeof(uint32_t));
	}
	sclasstab[fsclassid].keep_labelscnt = keep_labelscnt;
	for (i=0 ; i<keep_labelscnt ; i++) {
		memcpy(sclasstab[fsclassid].keep_labelmasks[i],keep_labelmasks+(i*MASKORGROUP),MASKORGROUP*sizeof(uint32_t));
	}
	sclasstab[fsclassid].arch_labelscnt = arch_labelscnt;
	for (i=0 ; i<arch_labelscnt ; i++) {
		memcpy(sclasstab[fsclassid].arch_labelmasks[i],arch_labelmasks+(i*MASKORGROUP),MASKORGROUP*sizeof(uint32_t));
	}
	sclasstab[fsclassid].arch_delay = arch_delay;
	sclass_fix_has_labels_fields(fsclassid);
	meta_version_inc();
	return MFS_STATUS_OK;
}
コード例 #6
0
ファイル: storageclass.c プロジェクト: onlyjob/moosefs
static inline uint8_t sclass_univ_duplicate_entry(uint8_t oldnleng,const uint8_t *oldname,uint8_t newnleng,const uint8_t *newname,uint16_t essclassid,uint16_t edsclassid) {
	uint32_t sclassid,fssclassid,fdsclassid;
	uint32_t i;
	if (sclass_name_check(oldnleng,oldname)==0 || sclass_name_check(newnleng,newname)==0 || (essclassid==0 && edsclassid>0) || (edsclassid==0 && essclassid>0)) {
		return MFS_ERROR_EINVAL;
	}
	fssclassid = 0;
	for (sclassid=1 ; fssclassid==0 && sclassid<firstneverused ; sclassid++) {
		if (sclasstab[sclassid].nleng==oldnleng && memcmp(sclasstab[sclassid].name,oldname,oldnleng)==0) {
			fssclassid = sclassid;
		}
	}
	if (fssclassid==0) {
		return MFS_ERROR_NOSUCHCLASS;
	}
	if (essclassid!=0 && fssclassid!=essclassid) {
		return MFS_ERROR_MISMATCH;
	}
	fdsclassid = 0;
	for (sclassid=1 ; sclassid<firstneverused ; sclassid++) {
		if (sclasstab[sclassid].nleng==newnleng && memcmp(sclasstab[sclassid].name,newname,newnleng)==0) {
			return MFS_ERROR_CLASSEXISTS;
		}
		if (sclasstab[sclassid].nleng==0 && fdsclassid==0) {
			fdsclassid = sclassid;
		}
	}
	if (fdsclassid==0) {
		if (firstneverused==MAXSCLASS) {
			return MFS_ERROR_CLASSLIMITREACH;
		}
		fdsclassid = firstneverused;
		firstneverused++;
	}
	if (edsclassid!=0 && fdsclassid!=edsclassid) {
		return MFS_ERROR_MISMATCH;
	}
	sclasstab[fdsclassid].nleng = newnleng;
	memcpy(sclasstab[fdsclassid].name,newname,newnleng);
	sclasstab[fdsclassid].admin_only = sclasstab[fssclassid].admin_only;
	sclasstab[fdsclassid].create_mode = sclasstab[fssclassid].create_mode;
	sclasstab[fdsclassid].create_labelscnt = sclasstab[fssclassid].create_labelscnt;
	for (i=0 ; i<sclasstab[fssclassid].create_labelscnt ; i++) {
		memcpy(sclasstab[fdsclassid].create_labelmasks[i],sclasstab[fssclassid].create_labelmasks[i],MASKORGROUP*sizeof(uint32_t));
	}
	sclasstab[fdsclassid].has_create_labels = sclasstab[fssclassid].has_create_labels;
	sclasstab[fdsclassid].keep_labelscnt = sclasstab[fssclassid].keep_labelscnt;
	for (i=0 ; i<sclasstab[fssclassid].keep_labelscnt ; i++) {
		memcpy(sclasstab[fdsclassid].keep_labelmasks[i],sclasstab[fssclassid].keep_labelmasks[i],MASKORGROUP*sizeof(uint32_t));
	}
	sclasstab[fdsclassid].has_keep_labels = sclasstab[fssclassid].has_keep_labels;
	sclasstab[fdsclassid].arch_labelscnt = sclasstab[fssclassid].arch_labelscnt;
	for (i=0 ; i<sclasstab[fssclassid].arch_labelscnt ; i++) {
		memcpy(sclasstab[fdsclassid].arch_labelmasks[i],sclasstab[fssclassid].arch_labelmasks[i],MASKORGROUP*sizeof(uint32_t));
	}
	sclasstab[fdsclassid].has_arch_labels = sclasstab[fssclassid].has_arch_labels;
	sclasstab[fdsclassid].arch_delay = sclasstab[fssclassid].arch_delay;
	if (essclassid==0 && edsclassid==0) {
		changelog("%"PRIu32"|SCDUP(%s,%s):%"PRIu32",%"PRIu32,main_time(),changelog_escape_name(oldnleng,oldname),changelog_escape_name(newnleng,newname),fssclassid,fdsclassid);
	} else {
		meta_version_inc();
	}
	return MFS_STATUS_OK;
}