Exemplo n.º 1
0
bool remove_oplock(files_struct *fsp)
{
	bool ret;
	struct share_mode_lock *lck;

	DEBUG(10, ("remove_oplock called for %s\n",
		   fsp_str_dbg(fsp)));

	/* Remove the oplock flag from the sharemode. */
	lck = get_existing_share_mode_lock(talloc_tos(), fsp->file_id);
	if (lck == NULL) {
		DEBUG(0,("remove_oplock: failed to lock share entry for "
			 "file %s\n", fsp_str_dbg(fsp)));
		return False;
	}

	ret = remove_share_oplock(lck, fsp);
	if (!ret) {
		DEBUG(0,("remove_oplock: failed to remove share oplock for "
			 "file %s, %s, %s\n",
			 fsp_str_dbg(fsp), fsp_fnum_dbg(fsp),
			 file_id_string_tos(&fsp->file_id)));
	}
	release_file_oplock(fsp);

	ret = update_num_read_oplocks(fsp, lck);
	if (!ret) {
		DEBUG(0, ("%s: update_num_read_oplocks failed for "
			 "file %s, %s, %s\n",
			  __func__, fsp_str_dbg(fsp), fsp_fnum_dbg(fsp),
			 file_id_string_tos(&fsp->file_id)));
	}

	TALLOC_FREE(lck);
	return ret;
}
Exemplo n.º 2
0
bool remove_oplock(files_struct *fsp)
{
	bool ret;
	struct share_mode_lock *lck;

	DEBUG(10, ("remove_oplock called for %s\n",
		   fsp_str_dbg(fsp)));

	/* Remove the oplock flag from the sharemode. */
	lck = get_existing_share_mode_lock(talloc_tos(), fsp->file_id);
	if (lck == NULL) {
		DEBUG(0,("remove_oplock: failed to lock share entry for "
			 "file %s\n", fsp_str_dbg(fsp)));
		return False;
	}

	if (fsp->oplock_type == LEVEL_II_OPLOCK) {

		/*
		 * If we're the only LEVEL_II holder, we have to remove the
		 * have_read_oplocks from the brlock entry
		 */

		struct share_mode_data *data = lck->data;
		uint32_t i, num_level2;

		num_level2 = 0;
		for (i=0; i<data->num_share_modes; i++) {
			if (data->share_modes[i].op_type == LEVEL_II_OPLOCK) {
				num_level2 += 1;
			}
			if (num_level2 > 1) {
				/*
				 * No need to count them all...
				 */
				break;
			}
		}

		if (num_level2 == 1) {
			/*
			 * That's only us. We are dropping that level2 oplock,
			 * so remove the brlock flag.
			 */
			struct byte_range_lock *brl;

			brl = brl_get_locks(talloc_tos(), fsp);
			if (brl) {
				brl_set_have_read_oplocks(brl, false);
				TALLOC_FREE(brl);
			}
		}
	}

	ret = remove_share_oplock(lck, fsp);
	if (!ret) {
		DEBUG(0,("remove_oplock: failed to remove share oplock for "
			 "file %s, %s, %s\n",
			 fsp_str_dbg(fsp), fsp_fnum_dbg(fsp),
			 file_id_string_tos(&fsp->file_id)));
	}
	release_file_oplock(fsp);
	TALLOC_FREE(lck);
	return ret;
}