All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bart Van Assche <bvanassche-HInyCGIudOg@public.gmane.org>
To: Hal Rosenstock
	<hal-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>,
	"linux-rdma
	(linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org)"
	<linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Cc: Vladimir Koushnir <vladimirk-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Subject: Re: [PATCH opensm] Implement atomic update operation for sa_db_file
Date: Wed, 13 Nov 2013 19:00:18 +0100	[thread overview]
Message-ID: <5283BE32.5070804@acm.org> (raw)
In-Reply-To: <5283A88D.9020608-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>

On 11/13/13 17:27, Hal Rosenstock wrote:
>
> From: Vladimir Koushnir <vladimirk-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
>
> Signed-off-by: Vladimir Koushnir <vladimirk-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
> ---
>   opensm/osm_sa.c |   20 ++++++++++++++++----
>   1 files changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/opensm/osm_sa.c b/opensm/osm_sa.c
> index 8c5ef5d..d5c1275 100644
> --- a/opensm/osm_sa.c
> +++ b/opensm/osm_sa.c
> @@ -525,25 +525,37 @@ opensm_dump_to_file(osm_opensm_t * p_osm, const char *file_name,
>   		    void (*dump_func) (osm_opensm_t * p_osm, FILE * file))
>   {
>   	char path[1024];
> +	char path_tmp[1032];
>   	FILE *file;
> +	int status = 0;
>
>   	snprintf(path, sizeof(path), "%s/%s",
>   		 p_osm->subn.opt.dump_files_dir, file_name);
>
> -	file = fopen(path, "w");
> +	snprintf(path_tmp, sizeof(path_tmp), "%s.tmp", path);
> +
> +	file = fopen(path_tmp, "w");
>   	if (!file) {
>   		OSM_LOG(&p_osm->log, OSM_LOG_ERROR, "ERR 4C01: "
>   			"cannot open file \'%s\': %s\n",
> -			file_name, strerror(errno));
> +			path_tmp, strerror(errno));
>   		return -1;
>   	}
>
> -	chmod(path, S_IRUSR | S_IWUSR);
> +	chmod(path_tmp, S_IRUSR | S_IWUSR);
>
>   	dump_func(p_osm, file);
>
>   	fclose(file);
> -	return 0;
> +
> +	status = rename(path_tmp, path);
> +	if (status) {
> +		OSM_LOG(&p_osm->log, OSM_LOG_ERROR, "ERR 4C0B: "
> +			"Failed to rename file:%s (err:%s)\n",
> +			path_tmp, strerror(errno));
> +	}
> +
> +	return status;
>   }
>
>   static void mcast_mgr_dump_one_port(cl_map_item_t * p_map_item, void *cxt)

Isn't an fdatasync() call missing after dump_func() and before fclose() 
? According to Theodore Ts'o calling fdatasync() or fsync() before 
fclose() is essential during an atomic update. See also 
http://thunk.org/tytso/blog/2009/03/15/dont-fear-the-fsync/ for more 
information.

Bart.

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2013-11-13 18:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-13 16:27 [PATCH opensm] Implement atomic update operation for sa_db_file Hal Rosenstock
     [not found] ` <5283A88D.9020608-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2013-11-13 18:00   ` Bart Van Assche [this message]
     [not found]     ` <5283BE32.5070804-HInyCGIudOg@public.gmane.org>
2013-11-22 14:57       ` Hal Rosenstock
     [not found]         ` <528F70BC.1050907-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
2013-11-22 15:27           ` Bart Van Assche

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5283BE32.5070804@acm.org \
    --to=bvanassche-hinycgiudog@public.gmane.org \
    --cc=hal-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org \
    --cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=vladimirk-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.