예제 #1
0
파일: linkea.c 프로젝트: AshishNamdev/linux
/**
 * Add a record to the end of link ea buf
 **/
int linkea_add_buf(struct linkea_data *ldata, const struct lu_name *lname,
		   const struct lu_fid *pfid)
{
	LASSERT(ldata->ld_leh);

	if (!lname || !pfid)
		return -EINVAL;

	ldata->ld_reclen = lname->ln_namelen + sizeof(struct link_ea_entry);
	if (ldata->ld_leh->leh_len + ldata->ld_reclen >
	    ldata->ld_buf->lb_len) {
		if (lu_buf_check_and_grow(ldata->ld_buf,
					  ldata->ld_leh->leh_len +
					  ldata->ld_reclen) < 0)
			return -ENOMEM;
	}

	ldata->ld_leh = ldata->ld_buf->lb_buf;
	ldata->ld_lee = ldata->ld_buf->lb_buf + ldata->ld_leh->leh_len;
	ldata->ld_reclen = linkea_entry_pack(ldata->ld_lee, lname, pfid);
	ldata->ld_leh->leh_len += ldata->ld_reclen;
	ldata->ld_leh->leh_reccount++;
	CDEBUG(D_INODE, "New link_ea name '" DFID ":%.*s' is added\n",
	       PFID(pfid), lname->ln_namelen, lname->ln_name);
	return 0;
}
예제 #2
0
/**
 * Add a record to the end of link ea buf
 **/
int linkea_add_buf(struct linkea_data *ldata, const struct lu_name *lname,
		   const struct lu_fid *pfid)
{
	struct link_ea_header *leh = ldata->ld_leh;
	int reclen;

	LASSERT(leh != NULL);

	if (lname == NULL || pfid == NULL)
		return -EINVAL;

	reclen = lname->ln_namelen + sizeof(struct link_ea_entry);
	if (unlikely(leh->leh_len + reclen > MAX_LINKEA_SIZE)) {
		/* Use 32-bits to save the overflow time, although it will
		 * shrink the cfs_time_current_sec() returned 64-bits value
		 * to 32-bits value, it is still quite large and can be used
		 * for about 140 years. That is enough. */
		leh->leh_overflow_time = cfs_time_current_sec();
		if (unlikely(leh->leh_overflow_time == 0))
			leh->leh_overflow_time++;

		CDEBUG(D_INODE, "No enough space to hold linkea entry '"
		       DFID": %.*s' at %u\n", PFID(pfid), lname->ln_namelen,
		       lname->ln_name, leh->leh_overflow_time);
		return 0;
	}

	if (leh->leh_len + reclen > ldata->ld_buf->lb_len) {
		if (lu_buf_check_and_grow(ldata->ld_buf,
					  leh->leh_len + reclen) < 0)
			return -ENOMEM;

		leh = ldata->ld_leh = ldata->ld_buf->lb_buf;
	}

	ldata->ld_lee = ldata->ld_buf->lb_buf + leh->leh_len;
	ldata->ld_reclen = linkea_entry_pack(ldata->ld_lee, lname, pfid);
	leh->leh_len += ldata->ld_reclen;
	leh->leh_reccount++;
	CDEBUG(D_INODE, "New link_ea name '"DFID":%.*s' is added\n",
	       PFID(pfid), lname->ln_namelen, lname->ln_name);
	return 0;
}