📄 file.c
字号:
/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * * Lustre Light file operations * * Copyright (c) 2002-2004 Cluster File Systems, Inc. * * This file is part of Lustre, http://www.lustre.org. * * Lustre is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. * * Lustre is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Lustre; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */#define DEBUG_SUBSYSTEM S_LLITE#include <stdlib.h>#include <string.h>#include <assert.h>#include <time.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/queue.h>#include <fcntl.h>#include <sysio.h>#ifdef HAVE_XTIO_H#include <xtio.h>#endif#include <fs.h>#include <mount.h>#include <inode.h>#ifdef HAVE_FILE_H#include <file.h>#endif#undef LIST_HEAD#include "llite_lib.h"/* Pack the required supplementary groups into the supplied groups array. * If we don't need to use the groups from the target inode(s) then we * instead pack one or more groups from the user's supplementary group * array in case it might be useful. Not needed if doing an MDS-side upcall. */void ll_i2gids(__u32 *suppgids, struct inode *i1, struct inode *i2){ LASSERT(i1 != NULL); LASSERT(suppgids != NULL); if (in_group_p(i1->i_stbuf.st_gid)) suppgids[0] = i1->i_stbuf.st_gid; else suppgids[0] = -1; if (i2) { if (in_group_p(i2->i_stbuf.st_gid)) suppgids[1] = i2->i_stbuf.st_gid; else suppgids[1] = -1; } else { suppgids[1] = -1; }}void llu_prepare_mdc_op_data(struct mdc_op_data *data, struct inode *i1, struct inode *i2, const char *name, int namelen, int mode){ LASSERT(i1 != NULL || i2 != NULL); if (i1) { ll_i2gids(data->suppgids, i1, i2); ll_inode2fid(&data->fid1, i1); }else { ll_i2gids(data->suppgids, i2, i1); ll_inode2fid(&data->fid1, i2); } if (i2) ll_inode2fid(&data->fid2, i2); else memset(&data->fid2, 0, sizeof(data->fid2)); data->name = name; data->namelen = namelen; data->create_mode = mode; data->mod_time = CURRENT_TIME; data->data = NULL;}void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid){ struct intnl_stat *st = llu_i2stat(dst); valid &= src->o_valid; if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME)) CDEBUG(D_INODE,"valid "LPX64", cur time %lu/%lu, new %lu/%lu\n", src->o_valid, LTIME_S(st->st_mtime), LTIME_S(st->st_ctime), (long)src->o_mtime, (long)src->o_ctime); if (valid & OBD_MD_FLATIME && src->o_atime > LTIME_S(st->st_atime)) LTIME_S(st->st_atime) = src->o_atime; /* mtime is always updated with ctime, but can be set in past. As write and utime(2) may happen within 1 second, and utime's mtime has a priority over write's one, leave mtime from mds for the same ctimes. */ if (valid & OBD_MD_FLCTIME && src->o_ctime > LTIME_S(st->st_ctime)) { LTIME_S(st->st_ctime) = src->o_ctime; if (valid & OBD_MD_FLMTIME) LTIME_S(st->st_mtime) = src->o_mtime; } if (valid & OBD_MD_FLSIZE && src->o_size > st->st_size) st->st_size = src->o_size; /* optimum IO size */ if (valid & OBD_MD_FLBLKSZ) st->st_blksize = src->o_blksize; /* allocation of space */ if (valid & OBD_MD_FLBLOCKS && src->o_blocks > st->st_blocks) st->st_blocks = src->o_blocks;}int llu_local_open(struct llu_inode_info *lli, struct lookup_intent *it){ struct ptlrpc_request *req = it->d.lustre.it_data; struct ll_file_data *fd; struct mds_body *body; ENTRY; body = lustre_msg_buf(req->rq_repmsg, DLM_REPLY_REC_OFF, sizeof(*body)); LASSERT(body != NULL); /* reply already checked out */ /* and swabbed down */ LASSERT(lustre_rep_swabbed(req, DLM_REPLY_REC_OFF)); /* already opened? */ if (lli->lli_open_count++) RETURN(0); LASSERT(!lli->lli_file_data); OBD_ALLOC(fd, sizeof(*fd)); /* We can't handle this well without reorganizing ll_file_open and * ll_mdc_close, so don't even try right now. */ LASSERT(fd != NULL); memcpy(&fd->fd_mds_och.och_fh, &body->handle, sizeof(body->handle)); fd->fd_mds_och.och_magic = OBD_CLIENT_HANDLE_MAGIC; lli->lli_file_data = fd; mdc_set_open_replay_data(&fd->fd_mds_och, it->d.lustre.it_data); RETURN(0);}int llu_iop_open(struct pnode *pnode, int flags, mode_t mode){ struct inode *inode = pnode->p_base->pb_ino; struct llu_inode_info *lli = llu_i2info(inode); struct intnl_stat *st = llu_i2stat(inode); struct ll_file_data *fd; struct ptlrpc_request *request; struct lookup_intent *it; struct lov_stripe_md *lsm; int rc = 0; ENTRY; liblustre_wait_event(0); /* don't do anything for '/' */ if (llu_is_root_inode(inode)) RETURN(0); CDEBUG(D_VFSTRACE, "VFS Op:inode=%llu\n", (long long)st->st_ino); LL_GET_INTENT(inode, it); if (!it->d.lustre.it_disposition) { LBUG(); } rc = it_open_error(DISP_OPEN_OPEN, it); if (rc) GOTO(out_release, rc); rc = llu_local_open(lli, it); if (rc) LBUG(); if (!S_ISREG(st->st_mode)) GOTO(out_release, rc = 0); fd = lli->lli_file_data; lsm = lli->lli_smd; if (lsm == NULL) { if (fd->fd_flags & O_LOV_DELAY_CREATE) { CDEBUG(D_INODE, "object creation was delayed\n"); GOTO(out_release, rc); } } fd->fd_flags &= ~O_LOV_DELAY_CREATE; lli->lli_open_flags = flags & ~(O_CREAT | O_EXCL | O_TRUNC); out_release: request = it->d.lustre.it_data; ptlrpc_req_finished(request); it->it_op_release(it); OBD_FREE(it, sizeof(*it)); /* libsysio hasn't done anything for O_TRUNC. here we * simply simulate it as open(...); truncate(...); */ if (rc == 0 && (flags & O_TRUNC) && S_ISREG(st->st_mode)) { struct iattr attr; memset(&attr, 0, sizeof(attr)); attr.ia_size = 0; attr.ia_valid |= ATTR_SIZE | ATTR_RAW; rc = llu_setattr_raw(inode, &attr); if (rc) CERROR("error %d truncate in open()\n", rc); } liblustre_wait_event(0); RETURN(rc);}int llu_objects_destroy(struct ptlrpc_request *request, struct inode *dir){ struct mds_body *body; struct lov_mds_md *eadata; struct lov_stripe_md *lsm = NULL; struct obd_trans_info oti = { 0 }; struct obdo *oa; int rc; ENTRY; /* req is swabbed so this is safe */ body = lustre_msg_buf(request->rq_repmsg, REPLY_REC_OFF, sizeof(*body)); if (!(body->valid & OBD_MD_FLEASIZE)) RETURN(0); if (body->eadatasize == 0) { CERROR("OBD_MD_FLEASIZE set but eadatasize zero\n"); GOTO(out, rc = -EPROTO);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -