Skip to content

Commit

Permalink
Check in 1.8.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gwanglst committed Dec 18, 2024
1 parent 9ae28c3 commit e81535f
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 51 deletions.
2 changes: 1 addition & 1 deletion LSQUICCOMMIT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6ed1d09f503c2fc25c3a2b204224ecdad36e077c
d3582f34f0b8dcdb64b3d6b0a25d351bc96f8cdf
11 changes: 8 additions & 3 deletions dist/lsns/bin/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
this = sys.modules[__name__]
this.logged = None
this.serverRoot = '/usr/local/lsws'
this.min_uid = 0

def init_logging():
logging.basicConfig(format="%(asctime)s.%(msecs)03d" + " [%(levelname)s] %(message)s",
Expand Down Expand Up @@ -80,14 +81,17 @@ def get_def_min_uid():
return 1000

def get_min_uid():
if this.min_uid != 0:
return this.min_uid
fullfile = get_conf_file('lsns.conf')
try:
f = open(fullfile, 'r')
except Exception as err:
if this.logged is None:
logging.info('Error opening %s: %s, continuing with default min uid %d' % (fullfile, err, get_def_min_uid()))
this.logged = True
return get_def_min_uid()
this.min_uid = get_def_min_uid()
return this.min_uid
try:
uidstr = f.readline()
except Exception as err:
Expand All @@ -96,8 +100,9 @@ def get_min_uid():
this.logged = True
uidstr = str(get_def_min_uid())
f.close()
logging.debug('Using min uid: %d' % int(uidstr))
return int(uidstr)
this.min_uid = int(uidstr)
logging.debug('Using min uid: %d' % this.min_uid)
return this.min_uid

def container_file():
return server_root() + "/lsns/conf/lscntr.txt"
Expand Down
7 changes: 5 additions & 2 deletions dist/lsns/bin/lscgctl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def list_user(user, dict):
subdict['cpu'] = get_systemctl_cpu(systemctl_results)
subdict['io'] = get_systemctl_dev_num(systemctl_results, 'IOReadBandwidthMax')
subdict['iops'] = get_systemctl_dev_num(systemctl_results, 'IOReadIOPSMax')
subdict['mem'] = get_systemctl_num(systemctl_results, "MemoryHigh")
subdict['mem'] = get_systemctl_num(systemctl_results, "MemoryMax")
subdict['tasks'] = get_systemctl_num(systemctl_results, 'TasksMax')
logging.debug("uid[" + str(user.pw_uid) + ']: ' + str(subdict))
dict[user.pw_uid] = subdict
Expand Down Expand Up @@ -194,7 +194,7 @@ def set_no_device_parm(args, option, properties):
val = common.int_num_values(args.cpu)
format_set = '%s=%d%%'
elif option == common.OPTION_MEM:
title = 'MemoryHigh'
title = 'MemoryMax'
val = common.int_num_values(args.mem)
format_set = '%s=%d'
else:
Expand All @@ -205,6 +205,9 @@ def set_no_device_parm(args, option, properties):
properties.append('%s=' % title)
else:
properties.append(format_set % (title, val))
if option == common.OPTION_MEM:
properties.append('MemoryHigh=')


def reset_user(args, user, reload):
args.cpu = '-1'
Expand Down
2 changes: 1 addition & 1 deletion dist/lsns/bin/lsnsctl
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def command_unmount(args, user):
print(result.stdout.decode('utf-8'))
print(result.stderr.decode('utf-8'))
if args.command == 'unmount-all':
common.restart_external(None, True)
common.restart_external([], True)
else:
common.restart_external([user], False)

Expand Down
15 changes: 9 additions & 6 deletions dist/lsns/bin/lspkgctl
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,16 @@ def plesk_home_dict():
def read_pleskplans():
home_dict = plesk_home_dict()
plans = {}
# Thanks to Stas Karpinsky of vangus.co.il for correcting the SQL!
plan_lines = run_program(['plesk', 'db', \
"SELECT sys_users.login, sys_users.home, " + \
"Templates.name from sys_users join " +
"PlansSubscriptions on " +
"PlansSubscriptions.subscription_id = sys_users.id " +
"join Templates on " +
"PlansSubscriptions.plan_id = Templates.id"])
"select sys_users.login, sys_users.home, " + \
"Templates.name from sys_users " + \
"join hosting on sys_users.id = hosting.sys_user_id " + \
"join domains on hosting.dom_id = domains.id " + \
"join Subscriptions on domains.id = Subscriptions.object_id " + \
"and Subscriptions.object_type = 'domain' " + \
"join PlansSubscriptions on Subscriptions.id = PlansSubscriptions.subscription_id " + \
"join Templates on PlansSubscriptions.plan_id = Templates.id"])
for line in plan_lines.splitlines():
if line.startswith('+-') or line.startswith('| login'):
continue
Expand Down
3 changes: 2 additions & 1 deletion src/h2/h2stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ int H2Stream::onPeerShutdown()
if (((H2Connection *)m_pH2Conn)->assignStreamHandler(this) == LS_FAIL)
return LS_FAIL;
}
if (getHandler()->detectContentLenMismatch(m_bufRcvd.size()))
if (getHandler()
&& getHandler()->detectContentLenMismatch(m_bufRcvd.size()))
return LS_FAIL;
return LS_OK;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/lshttpdmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
/***
* Do not change the below format, it will be set correctly while packing the code
*/
#define BUILDTIME "built: Sat Oct 26 04:05:54 UTC 2024"
#define BUILDTIME "built: Wed Dec 18 03:28:57 UTC 2024"

static const char s_pVersionFull[] = "LiteSpeed/" PACKAGE_VERSION
" Open (" LS_MODULE_VERSION_INFO_ONELINE ") BUILD (" BUILDTIME ")";
Expand Down
69 changes: 42 additions & 27 deletions src/shm/lsshm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,15 @@ void LsShm::setFatalErrorHandler( void (*cb)() )

void LsShm::tryRecoverBadOffset(LsShmOffset_t offset)
{
if (x_pShmMap->x_stat.m_iFileSize > offset)
LsShmSize_t curMaxSize = getMapFileSize();
if (curMaxSize > offset)
{
remap();
return;
}
deleteFile();
if (s_fatalErrorCb)
(*s_fatalErrorCb)();
LsShmSize_t curMaxSize = x_pShmMap->x_stat.m_iFileSize;
if ( offset < curMaxSize)
{
assert(offset < curMaxSize);
Expand All @@ -231,7 +231,8 @@ void LsShm::tryRecoverCorruption()

int LsShm::isOffsetValid(LsShmOffset_t offset)
{
return (offset <= x_pShmMap->x_stat.m_iFileSize);
LsShmSize_t curMaxSize = getMapFileSize();
return (offset <= curMaxSize);
}


Expand Down Expand Up @@ -527,8 +528,8 @@ LsShmStatus_t LsShm::newShmMap(LsShmSize_t size, uint64_t id)
return LSSHM_ERROR;
x_pShmMap->x_id = id;
x_pShmMap->x_globalHashOff = 0;
x_pShmMap->x_stat.m_iFileSize = size; // x_iMaxSize
x_pShmMap->x_stat.m_iUsedSize = LSSHM_SHM_UNITSIZE; // x_iCurSize
ls_atomic_set(&x_pShmMap->x_stat.m_iFileSize, size); // x_iMaxSize
ls_atomic_set(&x_pShmMap->x_stat.m_iUsedSize, LSSHM_SHM_UNITSIZE); // x_iCurSize

if (((x_pShmMap->x_iLockOffset = allocLock()) == 0)
|| (m_pShmLock = offset2pLock(x_pShmMap->x_iLockOffset)) == NULL
Expand Down Expand Up @@ -664,21 +665,23 @@ LsShmStatus_t LsShm::initShm(const char *mapName, LsShmXSize_t size,
m_pFileName, pShmMap->x_id, m_locks.getId());
return LSSHM_BADVERSION;
}

if (pShmMap->x_stat.m_iFileSize != mystat.st_size)
LsShmXSize_t fileSize = ls_atomic_value(&pShmMap->x_stat.m_iFileSize);
if (fileSize != mystat.st_size)
{
SHM_WARN("SHM file [%s] size: %lld, does not match x_stat.m_iFileSize: %ld, correct it",
m_pFileName, mystat.st_size, (long)pShmMap->x_stat.m_iFileSize);
pShmMap->x_stat.m_iFileSize = mystat.st_size;
m_pFileName, mystat.st_size, (long)fileSize);
ls_atomic_set(&pShmMap->x_stat.m_iFileSize, mystat.st_size);
fileSize = mystat.st_size;
}

// expand the file if needed... won't shrink
if (size > pShmMap->x_stat.m_iFileSize)
if (size > fileSize)
{
if (expandFile((LsShmOffset_t)pShmMap->x_stat.m_iFileSize,
(LsShmXSize_t)(size - pShmMap->x_stat.m_iFileSize)) != LSSHM_OK)
if (expandFile((LsShmOffset_t)fileSize,
(LsShmXSize_t)(size - fileSize)) != LSSHM_OK)
return LSSHM_ERROR;
pShmMap->x_stat.m_iFileSize = size;
fstat(m_iFd, &mystat);
ls_atomic_set(&pShmMap->x_stat.m_iFileSize, mystat.st_size);
}
else
size = mystat.st_size;
Expand Down Expand Up @@ -712,14 +715,21 @@ LsShmStatus_t LsShm::initShm(const char *mapName, LsShmXSize_t size,
// will not shrink at the current moment
LsShmStatus_t LsShm::expand(LsShmXSize_t incrSize)
{
LsShmXSize_t xsize = x_pShmMap->x_stat.m_iFileSize;

LsShmXSize_t xsize = getMapFileSize();
struct stat st;
if (expandFile((LsShmOffset_t)xsize, incrSize) != LSSHM_OK)
return LSSHM_ERROR;

//unmap();
xsize += incrSize;
x_pShmMap->x_stat.m_iFileSize = xsize;
fstat(m_iFd, &st);
if (st.st_size != xsize)
{
SHM_WARN("LsShm::expand() [%s], after exapnd, expected size: %d, actual size: %lld",
m_pFileName, xsize, st.st_size);
xsize = st.st_size;
}
ls_atomic_set(&x_pShmMap->x_stat.m_iFileSize, xsize);

if (mapAddrMap(xsize) != LSSHM_OK)
{
Expand Down Expand Up @@ -759,12 +769,14 @@ LsShmStatus_t LsShm::remap()
struct stat mystat;
if (fstat(m_iFd, &mystat) < 0)
return LSSHM_BADMAPFILE;
if (mystat.st_size != x_pShmMap->x_stat.m_iFileSize)

LsShmXSize_t xsize = getMapFileSize();
if (mystat.st_size != xsize)
{
setErrMsg(LSSHM_SYSERROR, "%s: real file size: %lu, SHM stats file size: %lu.",
m_pFileName, (unsigned long)mystat.st_size,
(unsigned long)x_pShmMap->x_stat.m_iFileSize);
if ( x_pShmMap->x_stat.m_iFileSize - mystat.st_size > 100 * 1024 * 1024)
(unsigned long)xsize);
if ( xsize - mystat.st_size > 100 * 1024 * 1024)
{
#ifndef NDEBUG
LsShmMap mapCopy = *x_pShmMap;
Expand All @@ -775,10 +787,10 @@ LsShmStatus_t LsShm::remap()

assert(mapCopy.x_stat.m_iFileSize > 0 && !"bad file size.");
}
xsize = mystat.st_size;
}
LsShmXSize_t size = x_pShmMap->x_stat.m_iFileSize;
//unmap();
return mapAddrMap(size);
return mapAddrMap(xsize);
}


Expand Down Expand Up @@ -809,36 +821,39 @@ LsShmOffset_t LsShm::allocPage(LsShmSize_t pagesize)
LsShmXSize_t needSize = 0;
LsShmXSize_t targetSize = 0;
// Allocate from heap space
LsShmXSize_t used_size = getUsedSize();
availSize = avail();
LsShmSize_t availAddrSize = m_addrMap.getAvailAddrSpace(
x_pShmMap->x_stat.m_iUsedSize, pagesize);
used_size, pagesize);
if (pagesize > availSize || pagesize > availAddrSize)
{
// min 16 unit at a time

LS_DBG("[SHM] [PID:%d] To alloc page: %d bytes at offset: %ld, availAddr: %d\n",
getpid(), pagesize, (long)x_pShmMap->x_stat.m_iUsedSize, availAddrSize);
getpid(), pagesize, (long)used_size, availAddrSize);
if (pagesize > availAddrSize)
needSize = availAddrSize;
if (pagesize + needSize > availSize)
needSize += (pagesize + needSize - availSize);

if (needSize > 0)
{
targetSize = x_pShmMap->x_stat.m_iFileSize + needSize;
LsShmXSize_t xsize = getMapFileSize();
targetSize = xsize + needSize;
targetSize = (targetSize + (16 * LSSHM_SHM_UNITSIZE - 1)) &
~(16 * LSSHM_SHM_UNITSIZE - 1);

if (expand(targetSize - x_pShmMap->x_stat.m_iFileSize) != LSSHM_OK)
if (expand(targetSize - xsize) != LSSHM_OK)
{
offset = 0;
goto out;
}
}
used_size = getUsedSize();
availAddrSize = m_addrMap.getAvailAddrSpace(used_size, pagesize);
if (pagesize > availAddrSize)
{
m_pGPool->addLeftOverPages(x_pShmMap->x_stat.m_iUsedSize,
availAddrSize);
m_pGPool->addLeftOverPages(used_size, availAddrSize);
used(availAddrSize);
}
}
Expand Down
17 changes: 11 additions & 6 deletions src/shm/lsshm.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ class LsShm : public ls_shm_s
}

LsShmXSize_t shmMaxSize() const { return m_iMaxShmSize; }
LsShmXSize_t maxSize() const { return x_pStats->m_iFileSize; }
LsShmXSize_t getMapFileSize() const
{ return ls_atomic_value(&x_pStats->m_iFileSize); }
LsShmXSize_t getUsedSize() const
{ return ls_atomic_value(&x_pStats->m_iUsedSize); }

LsShmXSize_t oldMaxSize() const { return m_iMaxSizeO; }
const char *fileName() const { return m_pFileName; }
const char *mapName() const { return obj.m_pName; }
Expand Down Expand Up @@ -185,8 +189,9 @@ class LsShm : public ls_shm_s
}

LsShmXSize_t avail() const
{ return (x_pStats->m_iFileSize > x_pStats->m_iUsedSize)
? x_pStats->m_iFileSize - x_pStats->m_iUsedSize : 0; }
{ LsShmXSize_t file_size = getMapFileSize();
LsShmXSize_t used = getUsedSize();
return (file_size > used) ? file_size - used : 0; }

LsShmStatus_t status() const { return m_status; }

Expand Down Expand Up @@ -215,7 +220,7 @@ class LsShm : public ls_shm_s

ls_attr_inline LsShmStatus_t chkRemap()
{
return (x_pStats->m_iFileSize == m_iMaxSizeO) ? LSSHM_OK : remap();
return (getMapFileSize() == m_iMaxSizeO) ? LSSHM_OK : remap();
}

LsShmStatus_t remap();
Expand Down Expand Up @@ -279,8 +284,8 @@ class LsShm : public ls_shm_s

void used(LsShmSize_t size)
{
assert(x_pStats->m_iFileSize >= x_pStats->m_iUsedSize + size);
x_pStats->m_iUsedSize += size;
assert(getMapFileSize() >= getUsedSize() + size);
ls_atomic_add(&x_pStats->m_iUsedSize, size);
}

LsShmStatus_t mapAddrMap(LsShmXSize_t size);
Expand Down
2 changes: 1 addition & 1 deletion src/shm/lsshmpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ bool LsShmPool::isFreeBlockBelow(
LsShmOffset_t offset, LsShmSize_t size, int joinFlag)
{
LsShmOffset_t belowOffset = offset + size;
if (belowOffset >= m_pShm->maxSize())
if (belowOffset >= m_pShm->getMapFileSize())
return false;

LShmFreeTop *ap = (LShmFreeTop *)offset2ptr(belowOffset);
Expand Down
2 changes: 1 addition & 1 deletion src/shm/lsshmpool.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class LsShmPool : public ls_shmpool_s
{ m_iAutoLock = 0; }

ls_attr_inline LsShmSize_t getShmMapMaxSize() const
{ return m_pShm->maxSize(); }
{ return m_pShm->getMapFileSize(); }

LsShmOffset_t getPoolMapStatOffset() const;

Expand Down

0 comments on commit e81535f

Please sign in to comment.