Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 298407 Details for
Bug 435291
LTC41974-Pages of a memory mapped NFS file get corrupted.
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
latest linked-list reproducer
mutex_lt3-7.c (text/plain), 5.37 KB, created by
Jeff Layton
on 2008-03-18 15:41:00 UTC
(
hide
)
Description:
latest linked-list reproducer
Filename:
MIME Type:
Creator:
Jeff Layton
Created:
2008-03-18 15:41:00 UTC
Size:
5.37 KB
patch
obsolete
>#include <stdio.h> >#include <stdlib.h> >#include <unistd.h> >#include <fcntl.h> >#include <sys/types.h> >#include <sys/stat.h> >#include <sys/mman.h> >#include <sys/wait.h> >#include <semaphore.h> >#include <string.h> >#include <errno.h> >#include <time.h> > >#define SEMKEY "mutex_lt3" >#define NRTHREADS 10 >#define MP (NRTHREADS + 1) > >struct x { > int val; > int next; >/* int garbage[1000]; */ > int garbage[1022]; >}; > >struct fs { > struct x pids[MP]; >}; > >void print_error(char *s) { > fprintf(stderr, "<%d> %s (%d:%s)\n", getpid(), s, errno, strerror(errno)); >} > >void print_message(char *s) { > fprintf(stderr, "<%d> %s\n", getpid(), s); >} > >void dump_list(pid_t pid, struct fs *fs) { > int i; > > for (i=0; i<MP; i++) { > printf("(%u) %d: val=%d next=%d\n", pid, i, fs->pids[i].val, > fs->pids[i].next); > } >} > >int main(int argc, char **argv) { > > int fd; > caddr_t addr; > struct fs *fsp; > struct fs b; > struct x *pp; > int flags = O_RDWR; > pid_t p1; > int i, j, iter = 0, loc; > int iterations = 400; > int count = 0; > int status; > int pstatus = 0; > sem_t *sem; > pid_t pid; > > srand((int)time(0)); > > memset(&b, 0, sizeof(b)); > > if (argc > 2) { > fprintf(stderr, "usage: %s <file>\n", argv[0]); > exit(1); > } > > unlink(argv[1]); > fd = open(argv[1], flags | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); > if (fd == -1) { > print_error("can't create specified file"); > exit(1); > } > > sem_unlink(SEMKEY); > sem = sem_open(SEMKEY, O_RDWR|O_CREAT|O_EXCL, 0600, 1); > if (sem == SEM_FAILED) { > print_error("sem_open failed"); > goto error_exit; > } > > write(fd, &b, sizeof(struct fs)); > > addr = mmap(0, sizeof(struct fs), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); > if (addr == MAP_FAILED) { > print_error("mmap failed"); > goto error_exit; > } > > fsp = (struct fs *)addr; > pp = fsp->pids; > > for (i=0; i<MP; i++) { > pp[i].val = -1; > pp[i].next = -1; > } > > if (msync((void *)addr, sizeof(struct fs), MS_SYNC) < 0) { > print_error("msync"); > } > if (munmap((char *)addr, sizeof(struct fs)) != 0) { > print_error("munmap"); > return 1; > } > if (close(fd) != 0) { > print_error("close"); > } > sem_close(sem); > > /* spawn children */ > printf("%u: ", getpid()); > fflush(stdout); > for (i=0; i < NRTHREADS; i++) { > pid = fork(); > if (pid < 0) { > print_error("fork"); > return 1; > } else if (pid == 0) { > goto child_task; > } else { > printf(" %u", pid); > fflush(stdout); > } > } > printf("\n"); > > while (i > 0) { > waitpid(-1, &status, 0); > if (WEXITSTATUS(status) != 0) > pstatus = WEXITSTATUS(status); > i--; > } > > return pstatus; > >child_task: > status = 0; > fd = open(argv[1], flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); > if (fd == -1) { > print_error("can't open specified file"); > return 1; > } > > sem = sem_open(SEMKEY, 0); > if (sem == SEM_FAILED) { > print_error("sem_open failed"); > goto error_exit; > } > > addr = mmap(0, sizeof(struct fs), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); > if (addr == MAP_FAILED) { > print_error("mmap failed"); > goto error_exit; > } > >#if 0 > status = madvise(addr, sizeof(struct fs), MADV_RANDOM); > if (status != 0) { > print_error("madvise failed"); > goto error_exit; > } >#endif > > fsp = (struct fs *)addr; > pp = fsp->pids; > > p1 = getpid(); > while (--iterations != 0) { > /* login: find first empty slot, insert into linked list */ > if ((status = sem_wait(sem))) { > print_error("lock"); > goto clean_exit; > } > for (i=1;i<MP;i++) { > if (pp[i].val == -1) { > j = i; > break; > } > } > if (i==MP) { > print_message("ran out of space"); > status = -ENOSPC; > goto unlock_exit; > } > pp[j].next = pp[0].next; pp[0].next = j; pp[j].val = p1; > if ((status = sem_post(sem))) { > print_error("unlock"); > goto clean_exit; > } > > /* do something to hold the mutex for a small time */ >// for (loc = 0; loc < 1000000; loc++) i *= 3; >// for (loc = 0; loc < 500000; loc++) i *= 3; >// usleep(1); > > /* logout: find my number and remove it */ > if ((status = sem_wait(sem))) { > print_error("lock"); > goto clean_exit; > } > i = 0; loc=0; iter = 0; > while (pp[i].next != -1) { > if (pp[pp[i].next].val == p1) { > pp[pp[i].next].val = -1; > j = pp[i].next; > pp[i].next = pp[pp[i].next].next; > pp[j].next = -1; > loc=1; > break; > } > /* shouldn't need to traverse list but once */ > if (iter > MP) { > fprintf(stderr, "<%d> looped 1\n", p1); > dump_list(p1, fsp); > status = 1; > goto unlock_exit; > } > i = pp[i].next; > iter++; > } > if (!loc) { > fprintf(stderr, "<%d> can't find me to logout - expected at slot %d\n", p1, j); > dump_list(p1, fsp); > status = 1; > goto unlock_exit; > } > if ((status = sem_post(sem))) { > print_error("unlock"); > goto clean_exit; > } > > /* integrity check */ > if ((status = sem_wait(sem))) { > print_error("lock"); > goto clean_exit; > } > i = 0; iter=0; > while (pp[i].next != -1) { > iter++; > i = pp[i].next; > if (iter>MP) { > fprintf(stderr, "<%d> looped 2\n", p1); > dump_list(p1, fsp); > status = 1; > goto unlock_exit; > } > } > > if ((status = sem_post(sem))) { > print_error("unlock"); > goto clean_exit; > } > count += 1; > } > > goto clean_exit; > >unlock_exit: > if (sem_post(sem)) { > print_error("unlock"); > } > >clean_exit: > if (msync((void *)addr, sizeof(struct fs), MS_SYNC) < 0) { > print_error("msync"); > } > if (munmap((char *)addr, sizeof(struct fs)) != 0) { > print_error("munmap"); > } >error_exit: > if (close(fd) != 0) { > print_error("close"); > } > > sem_close(sem); > //fprintf(stderr, "<%d> done, count =%d\n", p1, count); > return status; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 435291
:
296231
|
296232
|
297648
|
297649
| 298407 |
306161
|
309133