From: Gregory Giguashvili <Gregoryg@ParadigmGeo.com>
To: "'Andi Kleen'" <ak@suse.de>
Cc: linux-kernel@vger.kernel.org
Subject: RE: Problem with msync system call
Date: Tue, 23 Jul 2002 20:45:07 +0200 [thread overview]
Message-ID: <EE83E551E08D1D43AD52D50B9F511092E114A4@ntserver2> (raw)
[-- Attachment #1: Type: text/plain, Size: 349 bytes --]
>Do a F_SETFL lock/unlock on the file That should act as a
>full NFS write barrier and flush all buffers. Best is if you synchronize
>between the various writers with the full lock.
Do you mean F_SETLK? If so, this didn't help (the source is attached).
If you meant something else, could you be more specific, please?
Thanks in advance.
Giga
[-- Attachment #2: mmap.cc --]
[-- Type: application/octet-stream, Size: 2042 bytes --]
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main (int argc, char* argv [])
{
char buffer [BUFSIZ];
char* pMap;
int fd = open ("MAPPED.FILE", O_CREAT | O_RDWR | O_SYNC, 0666);
if (fd == -1) {
perror ("open");
return -1;
}
if (lseek (fd, BUFSIZ - 1, SEEK_SET) == -1) {
perror ("lseek");
return -1;
}
write (fd, "\0", 1);
if (lseek (fd, 0, SEEK_SET) == -1) {
perror ("lseek");
return -1;
}
pMap = (char*) mmap (NULL, BUFSIZ, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0);
if ((size_t) pMap == -1) {
perror ("mmap");
return -1;
}
while (1) {
fprintf (stderr, "<Press ENTER to read> OR <Enter string to write> $ ");
fgets (buffer, sizeof (buffer) - 1, stdin);
#if 0
if (munmap (pMap, BUFSIZ)) {
perror ("munmap");
return -1;
}
pMap = (char*) mmap (NULL, BUFSIZ, PROT_READ | PROT_WRITE,
MAP_SHARED, fd, 0);
if ((size_t) pMap == -1) {
perror ("mmap");
return -1;
}
#endif
struct flock lck = {
F_WRLCK, /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK */
SEEK_SET, /* Where `l_start' is relative to (like `lseek') */
0, /* Offset where the lock begins */
0, /* Size of the locked area; zero means until EOF */
getpid () /* Process holding the lock */
};
if (fcntl (fd, F_SETLK, &lck)) {
perror ("fcntl");
return -1;
}
if (buffer [0] == '\n') {
fprintf (stderr, "Mapped file contents: %s\n", pMap);
} else {
strncpy (pMap, buffer, strlen (buffer) - 1);
fprintf (stderr, "Written to mapped file: %s\n", pMap);
}
if (msync (pMap, BUFSIZ, MS_SYNC | MS_INVALIDATE)) {
perror ("msync");
return -1;
}
lck.l_type = F_UNLCK;
if (fcntl (fd, F_SETLK, &lck)) {
perror ("fcntl");
return -1;
}
}
return 0;
}
next reply other threads:[~2002-07-23 17:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-07-23 18:45 Gregory Giguashvili [this message]
2002-07-23 18:06 ` Andi Kleen
-- strict thread matches above, loose matches on Subject: below --
2002-07-23 19:36 Gregory Giguashvili
2002-07-23 19:04 Gregory Giguashvili
2002-07-23 18:00 Gregory Giguashvili
[not found] <EE83E551E08D1D43AD52D50B9F511092E1149F@ntserver2.suse.lists.linux.kernel>
2002-07-23 17:07 ` Andi Kleen
2002-07-23 18:01 ` Trond Myklebust
2002-07-23 16:58 Gregory Giguashvili
2002-07-23 16:31 ` Dr. Michael Weller
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=EE83E551E08D1D43AD52D50B9F511092E114A4@ntserver2 \
--to=gregoryg@paradigmgeo.com \
--cc=ak@suse.de \
--cc=linux-kernel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®