static int sli_open_backing_file(struct fidc_membh *f) { int lvl = PLL_DIAG, incr, rc = 0; char fidfn[PATH_MAX]; /* * XXX hit setrlimit: operation not permitted, but no open-fail. * This per open system call should go! Hit again due to fs.nr_open * sysctl limit. */ incr = psc_rlim_adj(RLIMIT_NOFILE, 1); sli_fg_makepath(&f->fcmh_fg, fidfn); fcmh_2_fd(f) = open(fidfn, O_CREAT|O_RDWR, 0600); if (fcmh_2_fd(f) == -1) { rc = errno; if (incr) psc_rlim_adj(RLIMIT_NOFILE, -1); OPSTAT_INCR("open-fail"); lvl = PLL_WARN; } else OPSTAT_INCR("open-succeed"); psclog(lvl, "opened backing file path=%s fd=%d rc=%d", strstr(fidfn, SL_RPATH_FIDNS_DIR), fcmh_2_fd(f), rc); return (rc); }
static int sli_open_backing_file(struct fidc_membh *f) { int lvl = PLL_DIAG, incr, rc = 0; char fidfn[PATH_MAX]; incr = psc_rlim_adj(RLIMIT_NOFILE, 1); sli_fg_makepath(&f->fcmh_fg, fidfn); fcmh_2_fd(f) = open(fidfn, O_CREAT|O_RDWR, 0600); if (fcmh_2_fd(f) == -1) { rc = errno; if (incr) psc_rlim_adj(RLIMIT_NOFILE, -1); OPSTAT_INCR("open-fail"); lvl = PLL_WARN; } else OPSTAT_INCR("open-succeed"); psclog(lvl, "opened backing file path=%s fd=%d rc=%d", strstr(fidfn, SL_RPATH_FIDNS_DIR), fcmh_2_fd(f), rc); return (rc); }
void sli_fcmh_dtor(__unusedx struct fidc_membh *f) { if (f->fcmh_flags & FCMH_IOD_BACKFILE) { if (close(fcmh_2_fd(f)) == -1) { OPSTAT_INCR("close-fail"); DEBUG_FCMH(PLL_ERROR, f, "dtor/close errno=%d", errno); } else OPSTAT_INCR("close-succeed"); psc_rlim_adj(RLIMIT_NOFILE, -1); f->fcmh_flags &= ~FCMH_IOD_BACKFILE; } }
void sli_fcmh_dtor(__unusedx struct fidc_membh *f) { struct fcmh_iod_info *fii; if (f->fcmh_flags & FCMH_IOD_BACKFILE) { if (close(fcmh_2_fd(f)) == -1) { OPSTAT_INCR("close-fail"); DEBUG_FCMH(PLL_ERROR, f, "dtor/close errno=%d", errno); } else OPSTAT_INCR("close-succeed"); psc_rlim_adj(RLIMIT_NOFILE, -1); f->fcmh_flags &= ~FCMH_IOD_BACKFILE; } if (f->fcmh_flags & FCMH_IOD_DIRTYFILE) { fii = fcmh_2_fii(f); lc_remove(&sli_fcmh_dirty, fii); f->fcmh_flags &= ~FCMH_IOD_DIRTYFILE; } }
/* * If the generation number changes, we assume a full truncation has * happened. We need to open a new backing file and attach it to the * fcmh. */ int sli_fcmh_reopen(struct fidc_membh *f, slfgen_t fgen) { int rc = 0; FCMH_LOCK_ENSURE(f); OPSTAT_INCR("reopen"); if (fgen == FGEN_ANY) { OPSTAT_INCR("generation-bogus"); return (EBADF); } if (fgen < fcmh_2_gen(f)) { OPSTAT_INCR("generation-stale"); return (ESTALE); } /* * If our generation number is still unknown try to set it here. */ if (fcmh_2_gen(f) == FGEN_ANY && fgen != FGEN_ANY) { OPSTAT_INCR("generation-fix"); fcmh_2_gen(f) = fgen; } if (fgen > fcmh_2_gen(f)) { struct sl_fidgen oldfg; char fidfn[PATH_MAX]; DEBUG_FCMH(PLL_DIAG, f, "reopening new backing file"); OPSTAT_INCR("slvr-remove-reopen"); slvr_remove_all(f); /* * It's possible the pruning of all slivers and bmaps * ended up fcmh_op_done() our fcmh so ensure it is * locked upon finishing. */ FCMH_RLOCK(f); /* * Need to reopen the backing file and possibly remove * the old one. */ if (f->fcmh_flags & FCMH_IOD_BACKFILE) { if (close(fcmh_2_fd(f)) == -1) { OPSTAT_INCR("close-fail"); DEBUG_FCMH(PLL_ERROR, f, "reopen/close errno=%d", errno); } else { OPSTAT_INCR("close-succeed"); } fcmh_2_fd(f) = -1; psc_rlim_adj(RLIMIT_NOFILE, -1); f->fcmh_flags &= ~FCMH_IOD_BACKFILE; } oldfg.fg_fid = fcmh_2_fid(f); oldfg.fg_gen = fcmh_2_gen(f); fcmh_2_gen(f) = fgen; rc = sli_open_backing_file(f); /* Notify upper layers that open() has failed. */ if (!rc) f->fcmh_flags |= FCMH_IOD_BACKFILE; /* Do some upfront garbage collection. */ sli_fg_makepath(&oldfg, fidfn); errno = 0; unlink(fidfn); DEBUG_FCMH(PLL_INFO, f, "upfront unlink(), errno=%d", errno); } else if (!(f->fcmh_flags & FCMH_IOD_BACKFILE)) { rc = sli_open_backing_file(f); if (!rc) f->fcmh_flags |= FCMH_IOD_BACKFILE; OPSTAT_INCR("generation-same"); } return (rc); }